Solved

Update a chart control as variables change

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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 …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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