如何刷新C#中的饼图 [英] How to refresh the piechart in C#

查看:113
本文介绍了如何刷新C#中的饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个方法,包括饼图的代码,并且我需要刷新图表的方法,但每当我点击我调用该方法的那些按钮时,饼图会自动复制该值。而且我也尝试了Refresh()和Update选项,但它不起作用。



我尝试过的事情:



公共部分类Form1:表格

{

public Form1()

{

InitializeComponent();

}



private void Form1_Load(object sender,EventArgs e)

{

chart();

}

private void chart()

{

chart1.Series [new]。Points.AddXY(Peter,1000);

chart1.Series [new]。Points.AddXY( Julia,1000);

}



private void button1_Click(object sender,EventArgs e)

{

chart();

}

}

I have made a method including the code of pie chart and call that method everywhere i need to refresh the chart, but whenever i click on those buttons where i have called the method then the pie chart duplicates the value automatically. And also i have tried Refresh() and Update option too but it doesn't work.

What I have tried:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
chart();
}
private void chart()
{
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}

private void button1_Click(object sender, EventArgs e)
{
chart();
}
}

推荐答案

你好,

更改方法代码: -

Hi,
change the method code:-
private void chart()
{
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}



这个: -


with this:-

private void chart()
{
chart1.Series.["new"].Points.Clear();
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}





正如@BillWoodruff所说每次调用图表()方法它为你的图表添加了额外的点,所以你需要清除以前的所有点,然后在图表中添加新点..



As @BillWoodruff says that every time you call the chart() method it added the extra points to your chart, so you need to clear the all the previous points and then add new points to the chart..


这篇关于如何刷新C#中的饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆