|
Rolling Chart |
Posted by Cadrogui on Apr-11-2010 06:22 |
|
I im working with Arduino and really need to hgraph on realtime the input data on the
serial port, ive recive the info, but i cant make the graph, anyone can helpme..
thnks
the code is an example of plugins
// The data for the line chart, Recive the info via SerialPort
dim data(-1) as double = Array(Val(PuertoSerial.ReadAll()))
// The labels for the line chart,
// the idea is get a point of the serial and graph with the time.
dim labels(-1) as string = array(fec.LongTime)
// Create a XYChart object of size 250 x 250 pixels
dim c as new CDXYChartMBS(510, 370)
// Set the plotarea at (30, 20) and of size 200 x 200 pixels
call c.setPlotArea(30, 20, 410,290)
// Add a line chart layer using the given data
call c.addLineLayer(data)
// Set the labels on the x axis.
call c.xAxis.setLabels(labels)
// Display 1 out of 3 labels on the x-axis.
c.xAxis.setLabelStep(3)
// Output the chart
grafico.Image = c.makeChartPicture |
Re: Rolling Chart |
Posted by Peter Kwan on Apr-12-2010 20:43 |
|
Hi Cadrogui,
You seem to be using the "Realbasic" edition of ChartDirector. This edition of ChartDirector is come one of our partners, and is not directly marketed by us. Personally, I am not familiar with "Realbasic", and are not sure what sample code is inclued in the "Realbasic" edition of ChartDirector.
I will try my best to help using the VB/VBScript language, which is somewhat similar to Realbasic.
In "ChartDirector for ASP/COM/VB", there is a "Realtime Chart" sample code included. In the documentation, there is a section called "Realtime Chart" that explains how to create a realtime chart. If similar sample code and documentation is available in the Realbasic edition of ChartDirector you are using, you may use them as a reference.
In your code, I am not sure what is "PuertoSerial.ReadAll()" (is it a number?), and what is "fec.LongTime" (is it a text string?). Anyway, to create a chart, you need a sequence of points (an array). You can pass the sequence to ChartDirector to create the chart.
In a realtime chart, when a new data value comes, your code would need to update the sequence. After your code have updated the sequence, you may pass the new sequence to ChartDirector to plot the chart.
In VB/VBScript, one way to update the sequence is like:
'Let's say we have a sequence of 200 numbers
ReDim myData(199)
ReDim myLabels(199)
.....
when a new data point arrive, you may update the sequence like:
'Shift the seqeunce to the left
For i = 1 To UBound(myData)
myData(i - 1) = myData(i)
Next
'add the new point to the right
myData(UBound(myData)) = newValue
... do the same for the myLabels ...
... Now you may use myData and myLabels to plot the chart ....
Hope this can help.
Regards
Peter Kwan |
|