Solved

Update a chart control as variables change

Posted on 2012-04-11
4
330 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

14 Experts available now in Live!

Get 1:1 Help Now