Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Chart Showing a "Location-Wise Active Employees" Doughnut chart...When I Click a Button The next Company Locations comes up...the problem is when i'm changing the company the chart loads successfully but Adding the Previous Company's Data too...i want to add just only the next company's location-wise data to the chart...I only need to know how to refresh the chart..Sorry for bad english
Thank you!

What I have tried:

I use this code to add data to the chart
VB
Chart1.Series(0).Points.AddXY(Value1,Value2)
Posted
Updated 21-Mar-19 16:01pm
Comments
lukeer 27-Mar-18 3:02am    
Is it in Windows Forms or XAML?
Which chart control do you use?
Member 13320940 27-Mar-18 22:42pm    
wndows forms,and ms charts

After the button is clicked, clear the Points collection before adding the new points.
 
Share this answer
 
v2
Comments
Member 13320940 27-Mar-18 12:00pm    
I tried Chart1.Series(0).Points.Clear()...
It didn't work..is there any other way to reset the values?
Anyway im gonna try it again...and i'll let you know
#realJSOP 27-Mar-18 12:48pm    
Re-instantiate the Chart.
Member 13320940 27-Mar-18 22:41pm    
How do i do that? "Re-Instantiate"?
I had a similar problem. I wanted to bring in new data and display it in place of the data that was already there. I was replacing the YValue[0] of existing Points. I could see, in the debugger, that the point data was being replaced, but the chart remained the same on the display. I found a Chart.Refresh() in the docs, but it wasn't in .NET 4.6.1. I found the Invalidate function in the object browser for Chart and to my surprise it worked! My code was like this:

C#
chart2.Series[0].Points[ix].YValues[0] = newvalue;
chart2.Invalidate();


I was trying to update the chart as each new data point arrived. However, your case might be different and you can use Chart.Invalidate(); wherever it make the most sense.
 
Share this answer
 
Comments
ivan chu 2021 3-May-21 3:35am    
Great! It works for me! I'm currently developing a simple Candle Stick Stock Chart that require a real-time update of those candle stick and redraw the chart. It stuck me for a whole day. Highly appreciate your idea! Thank you very much!

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