I'm trying to initialize the axes of a chart in C# with the following parameters:
chart1.ChartAreas[0].AxisX.Maximum = 20;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Interval = 5;
System.DateTime x1 = new System.DateTime(2016, 6, 8, 12, 00, 00);
System.DateTime x2 = new System.DateTime(2016, 6, 8, 23, 00, 00);
chart1.ChartAreas[0].AxisY.Maximum = x2.ToOADate();
chart1.ChartAreas[0].AxisY.Minimum = x1.ToOADate();
After running the above code I'm trying to add some data to the graph using:
DateTime x = DateTime.Now;
chart1.Series[0].Points.AddXY(i,x.ToOADate());
(where i gets incremented on subsequent data addition)
But, as soon as I initialize both the axis, the chart does not show any data.
If I don't set Y axis min and max, then it shows the following plot successfully.
How can i initialize both the axes and continue to plot data in the chart?
Thanks!
----- UPDATE 1 -----
It's working now. Changes made: In designer view, for the properties of chart, Charting/Series/YValueType was changed to DateTime. Before it was only Time.
Thanks!
AddXY()
, make sure you're not mixing upx
andy
coordinates. – jsanalytics