Recent

Author Topic: Looking for a TAchart (line) time example - or just help[SOLVED]  (Read 4458 times)

jbmckim

  • Full Member
  • ***
  • Posts: 144
I'm adding a new chart to an app.  It's a line graph where the intensity of a specific frequency is tracked over time.  The maximum amount of time is indeterminate.

In .Net, I have an analogous graph.  It automatically scales when the data set is less then the maximum number of points plotted on the x axis of the pane.  This is a setting in that environment.

In the new graph, I was thinking about doing something similar but using date/time as the x-axis.  The LazPas function set seems pretty rich in this regard.  What then, would be the best (probably that means easiest) way to have 3 or 4 date/time x-axis labels that scroll as points are added over time.  I looked for examples and gave it a slight go but there seems to be a fairly rich feature set associated with date time and it's a little hard for me at least to get all the pieces talking.

So, looking for a starting point example or guidance on how to build my own prototype.

Thanks.
« Last Edit: November 04, 2019, 08:20:12 pm by jbmckim »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help
« Reply #1 on: October 31, 2019, 12:21:29 am »
You mean that data are coming in and you want to plot as a function of time? At which rate? Since data collection time is not predetermined you probably want to see only the most recent data points, right? How many? What will happen with the older points? Are they dropped? Or are they kept in the chart and what you see only the right-most part of an ever-growing chart?

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help
« Reply #2 on: October 31, 2019, 05:37:27 am »
Thanks for responding. 

1) x is time, y is a value from an instrument. Not to beat it to death but just for clarity:  What volume did the instrument read at time t?

2) rate is the rate of the instrument capture.  This can be as high as twice a second but that would be the extreme case.

3) Yes, only the most recent points.  You ask, "how many?"  My other app rolls off at 250k.  If that or like isn't practical, 80-90k would be good (i.e.~the number of seconds in 24 hours).  All these points are saved to a DB but its helpful for the operator/developer to have a long term trend (longer is better).

4) As in 3, the older points can drop as all data is saved.

5) Yes, only the rightmost part of an every growing chart is desired.

I think that's all your questions.  Thanks for the detailed ask on your response.
« Last Edit: October 31, 2019, 05:53:14 am by jbmckim »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help
« Reply #3 on: October 31, 2019, 11:25:54 am »
Here is an example with probably does what you want to achieve. Adjust the parameters to fit your needs.

I used a timer to generate random y values at 250 ms intervals. Whenever the timer fires (i.e. a new data point "arrives") the method AddDataPoint is called with the the elapsed time and the new y value as parameters; the elapsed time is passed as a TDateTime, i.e. is counted in days. AddDataPoint adds the new data to the series' chartsource (by calling AddXY). It also queries the current extent from the series (LineSeries.Extent) which returns the smallest and largest x values in the a and b elements, i.e. ext.b.x - ext.a.x is the current range of times accumulated. When this range exceeds a given value (MAX_VIEWPORT, which is in secounds and thus must be divided by SECONDS_PER_DAY to be counted in days like the x values) all data points outside are deleted.

Since x values are given in day units a TDateTimeIntervalChartSource was added to the form and linked to the Marks.Source of the chart's BottomAxis; after setting Marks.Style to smsLabel the x values will automatically be converted to a convenient format, i.e. 'n:ss' for sort intervals, later hours will be added ('h:n:ss'), etc. (I am expecting a problem when the interval is longer than a day because then days will be added, but this will be calendar days! - Ask again if this should become a problem).

You may also want to set "SuppressPrevUnit" of the DataTimeIntervalChartSource to false to see all parts of the time labels.

In order to avoid the jittering display before the MAX_VIEWPORT is filled, I am forcing the chart's extent to this range (set Chart.Extent). This restriction is released once the data range is wider than the MAX_VIEWPORT so that the labels scroll with data arriving.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help
« Reply #4 on: October 31, 2019, 06:37:12 pm »
wp - Outstanding

I can use or adapt that as is (it's outstanding) but the opening bit (first few y plots) of the current program is hard to describe.  So taking your lead I put together an example of the current graph and the way it runs under a set scale until it runs into its display limits.  I'd like to mimic that if possible.  It's not a big deal and I can definitely manage with what you've done but it would be nice to be consistent between apps. (Both apps are used at different points in a manufacturing process.)

You'll need .Net 4 or greater to run this.  If you want the project (source) etc. just yell and I'll send it along. (It isn't much but might help you with the environment if you're interested.)

Background:  Zedgraph (an included dll and .Net, C# and VB.Net, add on) was featured in a CodeProject article 12 or so years ago.  The author (the late John Champion) did a hell of a job IMO of making the .Net graphics calls useful.  You can argue that he hid a few things but happily for me most of the stuff he hid were things that I don't care about controlling. ;)

I think TAChart is definitely more detailed and ultimately offers broader function.  And, like so much in LP, the fact that it is completely integrated into the compliler/dev environment is really good when deployment time comes or even when starting a new project.

Thanks again.


wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help
« Reply #5 on: October 31, 2019, 11:31:41 pm »
I am adding a new version of the demo which comes closer to your sample: Whenever the new x value runs out of the current x range the next xmax value is picked from a predefined array LIMITS. This version does not drop any old values any more.

NOTE: Although prepared for days this demo does not display the count of elapsed days correctly (calendar day instead of day count). Please ask again if your program will run for days so that this needs to be fixed.
« Last Edit: October 31, 2019, 11:34:49 pm by wp »

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help
« Reply #6 on: November 01, 2019, 06:22:27 pm »
With regard to the "startup" of the graph, you're dead on.  Excellent.

With regard to elapsed time, for my case it's accurate calendar/time that's required.  Imagine a production line operator shift change at a 24/7 mfg plant.  The new operator comes on and wants: 1) A thumbnail of the last 8 hours  2) Is that different than the previous day?  3) And maybe, hiccups that have occurred since that start of the current run.  Calendar time is much more important in this context than is count as it is like a the operator getting a status report of how things have been going before she takes over.   FYI, from other data in the app db, date/time is mappable to a given unit.  I think you're saying this should work.  If not, it's definitely something I'll need.  (This type of graph when used with the chart zoom is really useful.)

I'm debating whether I'll include a "Number of scans since start of current production run."  If I do though I'll display it as a non-editable textbox on the form that hosts the graph pane.  I can't think what the requirement would be that would drive the operator needing to know "Number of data acquisitions."


wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help
« Reply #7 on: November 01, 2019, 11:45:40 pm »
I am adding a final example which does not plot the "elapsed time" but simply the calendar date/time on the x axis.

Now I guess you have enough sample code and ideas to continue on your own.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #8 on: November 04, 2019, 08:19:34 pm »
Outstanding!  That's exactly it.

Hopefully others will find this helpful as well.  Don't mean to make work but long term, I'd think these or something much like would be helpful in the TAChart examples documentation. 

In addition to my current work, I've been thinking about doing an open source alarm/observation piece of software for hosting on SBC's (i.e. Raspberry et al).  This is an awesome capability for traffic (foot and vehicle) analysis.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #9 on: November 05, 2019, 07:22:15 pm »
wp - One more  :-X question.  How do I unlock the docking in your examples?  I'd like to add some things to the example myself before I port it all to something new but even though Halloween is over, I can't seem to get rid of the docking.

Thanks.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #10 on: November 05, 2019, 07:36:41 pm »
Docking? What do you mean?

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #11 on: November 05, 2019, 08:34:07 pm »
Docking/Anchoring.  The controls on the form all seem to be docked or maybe anchored (in .Net this behavior would be the result of both anchoring and docking) to the form and to each other.  Thus, in the IDE (as well as at run time) it's not possible to expand the form without expanding the hosted controls. 

I looked through the documentation on the subject but it's not clear (to me at least) how to shut this functionality off.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #12 on: November 05, 2019, 09:45:32 pm »
In the form of the project "indata_arriving_v2a.zip", anchoring is not used. The bottom panel is only aligned alBottom, the chart is client-aligned.

Quite often I use anchoring by means of the AnchorEditor ("View" > "Anchor Editor") because this is the only way to achieve a consistent layout across various widgetsets. Its drawback is that it is more complicated to add additional controls. Read https://wiki.lazarus.freepascal.org/IDE_Window:_Anchor_Editor.

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help
« Reply #13 on: November 06, 2019, 06:44:46 pm »
Ah!  It was the client alignment giving me my issue.

Thanks again.
« Last Edit: November 27, 2019, 08:58:25 pm by jbmckim »

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: Looking for a TAchart (line) time example - or just help[SOLVED]
« Reply #14 on: November 27, 2019, 10:21:48 pm »
wp -

I don't think this quite rises to the level of bug but there's a complication in using date time as it is here.  In the attachment which is derived from your examples with some extra debugging and function I'll use elsewhere later, the "reset" of the frame extents at the end of the LIMITS array (i.e. High(LIMITS) fails to execute because the LIMITS array value calculates to a different double value than does the x axis extent value because...double.  I'm not completely clear why it doesn't get to the "higher than" condition but it no longer increments when it has moved past the bounds of the current x extent.  In the excerpt below, the assignment never executes.  (Note that I played around some with the comparison.  Your original code is commented but behaved in the same manner.)

Code: Pascal  [Select][+][-]
  1.    if (CompareValue(rng,High(LIMITS)) = 1) or (CompareValue(rng,High(LIMITS)) = 0)then
  2.     //if rng > High(LIMITS) then
  3.       Chart1.Extent.XMax := Chart1.Extent.XMax + 1  

If you have time and interest I'm wondering if you can suggest a work around?  If not, thanks again for all your other help.

PS.  I've abbreviated the LIMITS array so that the entire bit exhausts its run in about a minute.  In addition, I'm only plotting every fourth clock tick as when we got into big numbers the process started to eat memory and cpu.  I've had this same thing happen with other environments doing approximately the same work.


 

TinyPortal © 2005-2018