简体   繁体   中英

Mschart - Bar Chart Not Updating in C#

In my project values are updating in every 1 second; Based on the values I am plotting Bar chart. What is happening is it is not updating and plotting real time values. For Example If Value is (30,10) it plots. If value is (30,45) it updates and plots. If value is (30,5) Chart not updates and not get plots.

Please Help what to do I have tried Chart1.Series["Series1"].Points.Clear(); but this is not working as my values are updating in every 1 second.

It seems you need to set a minimum and maximum for your chart Axis-Y or if you prefer, make the axis automatically reset its minimum and maximum.

If you set a specific minimum and maximum value for Axis-Y, then the chart Axis-Y will not change it's values automatically and when you add new point to chart, the Axis-Y values will not update and only the points will update:

chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 200;

Also you can set the chart to automatically change range for Aixs-Y, this way the Axis-Y updates it's minimum and maximum and your chart Axiy-Y changes:

chart1.ResetAutoValues();
//Or this
//chart.ChartAreas[0].RecalculateAxesScale()

As an example:

Put a Chart and a Timer on a form. Set the interval of Timer to 1000 ms, and set it's Enabled to true . Handle Load event of form and Tick event of timer and write these codes:

private void From1_Load(object sender, EventArgs e)
{
    chart1.Series.Clear();
    chart1.Series.Add("Serie1");
    chart1.ChartAreas[0].AxisY.Minimum = 0;
    chart1.ChartAreas[0].AxisY.Maximum = 200;
}

private void timer1_Tick(object sender, EventArgs e)
{
    int y = new Random().Next(0, 200);
    chart1.Series[0].Points.Clear();
    chart1.Series[0].Points.AddXY(30, y);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM