简体   繁体   English

Mschart-条形图未在C#中更新

[英]Mschart - Bar Chart Not Updating in C#

In my project values are updating in every 1 second; 在我的项目中,值每1秒更新一次; 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. 例如,如果Value为(30,10)则会进行绘制。 If value is (30,45) it updates and plots. 如果值为(30,45)则会更新并绘制。 If value is (30,5) Chart not updates and not get plots. 如果值为(30,5)图表不会更新,也不会获得图表。

Please Help what to do I have tried Chart1.Series["Series1"].Points.Clear(); 请帮我尝试过Chart1.Series["Series1"].Points.Clear(); but this is not working as my values are updating in every 1 second. 但这不起作用,因为我的值每1秒更新一次。

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. 似乎您需要为图表Axis-Y设置最小值和最大值,或者,如果愿意,请使该轴自动重置其最小值和最大值。

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: 如果您为Axis-Y设置了特定的最小值和最大值,则图表Axis-Y不会自动更改其值,并且当您向图表中添加新点时,Axis-Y值将不会更新,而只会更新这些点:

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: 您还可以将图表设置为自动更改Aixs-Y的范围,这样Axis-Y会更新其最小值和最大值,并且图表Axiy-Y也会更改:

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

As an example: 举个例子:

Put a Chart and a Timer on a form. ChartTimer放在窗体上。 Set the interval of Timer to 1000 ms, and set it's Enabled to true . 将Timer的间隔设置为1000 ms,并将其Enabled设置为true Handle Load event of form and Tick event of timer and write these codes: 处理表单的Load事件和计时器的Tick事件,并编写以下代码:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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