Solved

Update a chart control as variables change

Posted on 2012-04-11
4
331 Views
Last Modified: 2012-04-12
Hi All

One of the forms in my project has a basic line graph created using the chart control. It shows market size in units over 12 periods. The 12  Y-axis values are read from 12 text boxes that start with default values read from a file. The form's load event then has code that reads these into an array and creates a series to display on the graph. So far so good, the graph does display correctly.

What I want, however, is for the user to be able to enter new figures into the text boxes and for the graph to update automatically as the array variables are changed.

Any suggestions?

Regards

Terry
0
Comment
Question by:Terrygordon
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37833533
Assuming you only have one series associated with the chart, in the clickevent of the button to update (or the onleave event of the textbox), get the series associated with the chart, then you can set the value of theitem from there, e.g
Dim TheSeries = Chart1.Series.FirstOrDefault
'then set the value of the point
TheSeries.Points.Item(0).SetValueXY(12, "Jan")

Open in new window

PS. You may need to call Invalidate on the chart to redraw after changing the points
0
 

Author Comment

by:Terrygordon
ID: 37837725
Hi Nepaluz

I have tried a version of your suggestion, which seems to be working (once I'd remembered to call invalidate). Only problem is that the original line is staying on the chart and a new line is drawn representing the changes. I'd assumed that chart1.invalidate (), at the start of the update sub would remove the original line, but it hasn't. Any thoughts?

Regards

Terry
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37837886
try this
Dim TheSeries = Chart1.Series.FirstOrDefault
Chart1.Series.Clear()
TheSeries.Points.Item(0).SetValueXY(12, "Jan")
Chart1.Series.Add(TheSeries)
Chart1.Invalidate()

Open in new window

0
 

Author Comment

by:Terrygordon
ID: 37838140
Spot on! Although I had to put the Add statement before the SetValueXY statement.

Many thanks - full points on this one, but keep your eyes open, I'm about to enter more uncharted territory in the project (excuse the pun).

Regards

Terry
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now