Solved

Update a chart control as variables change

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …

739 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