VB 2008 Chart Control - 24 Hour Graph

macdaddy2005
macdaddy2005 used Ask the Experts™
on
Hello,

We've recently installed temperature sensors at our branch locations and set up a simple VB 2008 program to read the XML data and graph the temperature trend.  

I'm using the MS Chart Control addon to plot a line graph.  For the most part, everything is working as intended, however, I would like the graph to only show the last 24 hours worth of the graph.  

I have X axis as "Time"  and the Y axis as Temperature.  The X axis is set for VariableCount and the Y axis is Fixed between 65 and 85 F.  

What I would like to do is have the X axis remain Variable but only hold 24 hours worth of trend points.  After 24 hours, I'd like to see the graph start shifting left if for each new point if possible.

I played around with the Scale Min and Max a bit but couldn't get anything to work.  Anyone know of a way to get this to work?  I attached a picture of the output graph.

Here's a snipped of how the data is getting plotted in the graph

       
Dim lukepoint As Double = LUKTempF
        Dim arrowpoint As Double = ARHTempF
        Dim cactuspoint As Double = CTSTempF
        Dim northpoint As Double = NORTempF
        Dim heritagepoint As Double = HTGTempF
        Chart1.Series(0).XValueType = ChartValueType.DateTime
        Dim x As DateTime = DateTime.Now
        Dim y As String = x.ToString("H:mm:ss")
        Chart1.Series.Item("Luke").Points.AddXY(y, lukepoint)
        Chart1.Series.Item("Arrowhead").Points.AddXY(y, arrowpoint)
        Chart1.Series.Item("Cactus").Points.AddXY(y, cactuspoint)
        Chart1.Series.Item("North Mtn").Points.AddXY(y, northpoint)
        Chart1.Series.Item("Heritage").Points.AddXY(y, heritagepoint)

Open in new window

ExpertsExchange.JPG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
You can filter your data before assigning it to chart so that it only has last 24 hours of data. What's the structure of data? Do you load it to datatable first?

Author

Commented:
I'm not a VB expert, so my coding is pretty basic.

I'm plotting it directly to the chart control in realtime, not storing any data in a dataset.  

This is the flow of the code for just one of the series in the graph.

'Pull XML data
LUKxml.Load("http://10.10.2.3/data.xml")

'Select XML node
LUKnode = LUKxml.SelectSingleNode("//server/devices/device")

'Select XML Attribute Value
Dim LUKTempF = LUKnode.ChildNodes(1).Attributes("value").Value

'textbox for current temp
txtLUKtemp.Text = LUKTempF + " F"

Dim lukepoint As Double = LUKTempF
Chart1.Series(0).XValueType = ChartValueType.DateTime
Dim x As DateTime = DateTime.Now
Dim y As String = x.ToString("H:mm:ss")
Chart1.Series.Item("Luke").Points.AddXY(y, lukepoint)

Open in new window


I run a timer control to poll the XML data every 10 seconds
Most Valuable Expert 2012
Top Expert 2014
Commented:
>Dim x As DateTime = DateTime.Now

Where is the actual datetime? You can put an if condition

If (now - dateoftempreading).totalhours <= 24 Then
    plot data
else
    ignore value
end if

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial