sowjanya attaluri
sowjanya attaluri

Reputation: 911

axis object error - The minimum value of the axis is greater than the largest data point value in MS line chart in c#

I am developing windows forms application with MS date time line chart using C#.net. (x-axis datetime, y1-axis double value, y2-axis double value) I need to add data points (live data) to chart for every 10 seconds. Initially chart show 10 minutes data. After that, I am removing first data point and adding one data point at last ( simply shifting). For this, I am changing axis min max values. My application run successfully for a week, after that getting below error.

Axis Object - The minimum value of the axis is greater than the largest data point value.

Here is my code sample,

 if (datapointcount >= 600)    
 {           
    chart1.Series[0].Points.RemoveAt(0);                       
    chart1.ChartAreas[0].AxisX.Minimum = DateTime.FromOADate(chart1.Series[0].Points[0].XValue).ToOADate();
    chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(chart1.Series[0].Points[chart1.Series[0].Points.Count - 1].XValue).AddSeconds(10).ToOADate();
    chart1.ChartAreas[0].RecalculateAxesScale();   
 }

this.chart1.Series[0].Points.AddXY(xval , value1); 
this.chart1.Series[1].Points.AddXY(xval, value2);                   

chart1.Invalidate();    
chart1.Update();

Upvotes: 1

Views: 2786

Answers (2)

jkj56
jkj56

Reputation: 1

The problem for me was that I also have to convert my data to OADate()

this.chart1.Series[0].Points.AddXY(xval .ToOADate() , value1);

this.chart1.Series[1].Points.AddXY(xval .ToOADate(), value2);

Upvotes: 0

Andrew Skylight
Andrew Skylight

Reputation: 21

chart1.ChartAreas[0].AxisX.Minimum += 1;
chart1.ChartAreas[0].AxisX.Maximum += 1; 

Works for my application. I also add value first THEN adjust scales.

The error is thrown because AxisX.Maximum is less than AxisX.Minimum

Upvotes: 2

Related Questions