Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hi All

I am having difficulty in displaying all the months on a graph

The graph displays 12 months but the X Axis only shows every other month

How do i get that all month names display on the X Axis?

Thank you in advance

What I have tried:

I have tried resizing the chart and was hoping it would then fit everything in but it does not.

it is a setting within the chart properties or is it something that can be done with code?

chart1.Size = new Size(1200, 500);
chart1.Height = 450;
chart1.Titles.Add("Occupancy");
chartArea1.Position.Height = 80;
Posted
Updated 16-Mar-18 0:36am

1 solution

Try this:
        public class Data
            {
            public DateTime Date { get; set; }
            public int Value { get; set; }
            }
...
            List<Data> data = new List<Data>();
            for (int mon = 1; mon < 13; mon++)
                {
                data.Add(new Data() { Date = new DateTime(2018, mon, 1), Value = mon });
                }
            chart1.DataSource = data;
            chart1.Series[0].XValueMember = "Date";
            chart1.Series[0].YValueMembers = "Value";
            chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Months;
            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MMM";
            chart1.ChartAreas[0].AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
            chart1.ChartAreas[0].AxisX.Interval = 1;
            chart1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900