Author |
Topic |
|
soundar
51 Posts |
Posted - 01 Dec 2012 : 16:38:21
|
I had posted regarding a similar issue before but I am facing this again, this time with the rtAutoScrollGraph
I have a rtAutoScrollGraph (with 15 graphs) (based on the AutoGraphDemos example. I have a start and stop button in my form. When 'Start' is clicked data is piped to the UpdateScrollGraph function and when 'Stop' is clicked data acquisition is stopped.
When I click 'Start' again I want to clear the graph contents. I do this by
For i As Byte = 0 To rtAutoScrollGraph1.ProcessVariableArray.Count - 1 rtAutoScrollGraph1.GetProcessVariable(i).TruncateProcessVarDataset(0) Next This works but the graph starts scrolling from the middle or from the right, not from the left again. That is the left most point of the time axis is not set to the few first point.
I am pulling my hair over this. How do I reset the time axis limits? Dim starttime As ChartCalendar = New ChartCalendar Dim endtime As ChartCalendar = starttime endtime.Add(ChartCalendar.SECOND, clsConfigParam.GraphTimeRangeSec) rtAutoScrollGraph1.GraphScrollFrame.RescaleFrame(starttime.?what goes here, 0, endtime.?what goes here, 1)
----------- To put it another way, let us say I start the program at 1:00:00 and setup the time axis range to be 10 sec. The time axis now runs between 1:00:00 and 1:00:10 (approx). So far so good.
I do not click the start button right away, but wait for 5 min and then click it. The first point is piped at 1:05:00. But the time axis instead of starting at 1:05:00 (or thereabouts), starts at 1:04:50 and starts scrolling and I do not see the first point for about 5 sec. This gets worse and worse as I start and stop several times and in the RT_MAXEXTENT_FIXEDSTART_AUTOSCROLL mode, the graph starts scrolling from the right edge of the graph to the left edge. |
|
soundar
51 Posts |
Posted - 01 Dec 2012 : 17:35:23
|
Correction to my post: ------------------------ Say I start the program at 1:00:00 PM, set up the graph for a range of 1 min. The time axis correctly runs from 1:00:00 to 1:01:00
If I wait for 10 min, and click 'Start' at 1:10 then the time axis runs from 1:09 to 1:10 and then starts scrolling, instead of between 1:10 to 1:11. |
|
|
quinncurtis
1586 Posts |
Posted - 01 Dec 2012 : 19:03:24
|
If you want the left edge of the chart to synchronize with the initial start of your plotting, then scale the coordinate system of the scroll frame accordingly. The call to RescaleAxesToCurrentTransform is required to bring all of the axis and grid objects in sync with the new time.
ChartCalendar startTime = new ChartCalendar(); ChartCalendar endTime = new ChartCalendar(); . . // set startTime and endTime to the start and end of the desired data window . // Scale the starting and ending values using the millisecond equivalent of the ChartCalendar objects scrollFrame.ChartObjScale.ScaleStartX = startTime.GetCalendarMsecs(); scrollFrame.ChartObjScale.ScaleStopX = endTime.GetCalendarMsecs(); scrollFrame.RescaleAxesToCurrentTransform(); |
|
|
soundar
51 Posts |
Posted - 01 Dec 2012 : 23:31:23
|
Thanks for the quick response. It works!
One question though. When I tried this first, it did not work, raised an overflow exception. I had written the resetting code this way:
Dim starttime As ChartCalendar = New ChartCalendar Dim endtime As ChartCalendar = starttime endtime.Add(ChartCalendar.SECOND, 60) ...ScaleStartX etc...
Note that I had endtime=starttime and THEN add 60 sec to the end time. This raised an exception. But after I changed it to the way you have starttime = new chartcalendar endtime = new chartcalendar endtime.add.... it worked fine.
Can't understand why, but thanks for taking the time on a weekend to answer my question. |
|
|
quinncurtis
1586 Posts |
Posted - 02 Dec 2012 : 11:52:05
|
You can't set the starting and ending value of either the x- or y-scale of a chart to the same value, producing a zero range. This is like putting explicit divide by zero calculations in your program.
Your example code which fails produces only one ChartCalendar object, starttime.
Dim starttime As ChartCalendar = New ChartCalendar Dim endtime As ChartCalendar = starttime
In that case, starttime and endtime reference exactly the same ChartCalendar object, so changes made to one will also change the other, and they will always be identical. You must always create your ChartCalendar objects using New, or Clone it from an existing ChartCalendar, which you will see done in all of our programs in the data simulation area.
If you assign one object to another, you are assigning it by reference. What you expected was an assignment by value, which only what happens with base types (double, int, string, etc.).
|
|
|
|
Topic |
|
|
|