Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh piechart in c#

Tags:

c#

winforms

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.

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();
    }
}
like image 655
abcd Avatar asked Nov 08 '22 13:11

abcd


1 Answers

If I've understood the problem correctly, I think you simply need to clear down the Series' Points collection.

For example:

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

Is this what you were looking to do?

like image 96
Mike Bradley Avatar answered Nov 14 '22 21:11

Mike Bradley