?
Solved

Update a chart control as variables change

Posted on 2012-04-11
4
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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