Click here to Skip to main content
15,888,039 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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();
}
}
Posted
Updated 26-Jun-16 20:30pm
Comments
BillWoodruff 27-Jun-16 1:13am    
There's no mystery in your code: you call chart() and the points are added again.

To assist you further we really need to know what "chart" is, it it something you are drawing using the 'Paint Event of some Control; is it a 3rd. party component ?

And, what's happening that you need to refresh it ? Be specific.
Member 12605081 27-Jun-16 1:20am    
yes, i m using 3rd party component and i need to refresh it , i need a solution so can u please help me out
BillWoodruff 27-Jun-16 3:08am    
Understood, but what is the reason you need to refresh the visual appearance of the Chart when the data points have not changed ? What do your eyes SEE that is "wrong" ?

1 solution

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

with this:-
C#
private void chart()
{
chart1.Series.["new"].Points.Clear();
chart1.Series["new"].Points.AddXY("Peter", "1000");
chart1.Series["new"].Points.AddXY("Julia", "1000");
}


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..
 
Share this answer
 
Comments
BillWoodruff 27-Jun-16 3:09am    
"you need to clear the all the previous points"

imho, that is not something we can infer now from what the OP has told us ... so far.
JayantaChatterjee 27-Jun-16 4:10am    
Yes, you are right..
I think OP show us the static value to render the chart, but he may be dealing with the dynamic values.. that's why I'm post this solution..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900