刷新C#中的图表 [英] Refreshing a Chart in C#
本文介绍了刷新C#中的图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我使用C#在Windows窗体上绘制图表,图表正在使用数据库表。
任何人都可以告诉我,当更多数据插入数据库时,刷新图表的最简单方法是什么?
Hello,
I am drawing a Chart on Windows Form using C# and chart is using Database Table.
Can anyone please tell me, what is the easiest way to refresh the chart as more data is inserted into a database ?
推荐答案
你好,
您是否尝试过.Update()?
它将类似
Hi,
Have you tried the ".Update()"?
it will be something like
chart1.Update();
Jegan
chart1.UpDate();
更改为 chart1.Update();
(C#区分大小写)[/ Edit]
Jegan
chart1.UpDate();
changed into chart1.Update();
(C# is case-sensitive)[/Edit]
我创建了一个简单的图表,当我更新值时,相应的值应该在我的图表中更新而不使用Cahrt1.Update或chart1.Refresh();
你可以给这个解决方案
I have created a simple chart ,when i update the values,the corresponding value should update in my chart without using Cahrt1.Update or chart1.Refresh();
can you give solution for this
每次你给系列添加一个点时,图表会自动更新,
问题是你要从不同的线程更新图表,所以你需要调用这样的操作:
private void UpdateChar t()
{
if(chart1.InvokeRequired)
{
chart1.Invoke(new Action( ()=>
{
UpdateChart();
}
));
}
其他
{
chart1.Series [0] .Points.AddXY(100,200);
}
}
Every time you add a point to the series the chart will automatically update itself,
the thing is that you are updating the chart from a different thread so you need to invoke the operation like this :
private void UpdateChart()
{
if (chart1.InvokeRequired)
{
chart1.Invoke(new Action(() =>
{
UpdateChart();
}
));
}
else
{
chart1.Series[0].Points.AddXY(100,200);
}
}
这篇关于刷新C#中的图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文