Recent

Author Topic: [Solved] selecting chart data like with the Zoom Drag Tool  (Read 14854 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
[Solved] selecting chart data like with the Zoom Drag Tool
« on: June 21, 2021, 10:40:19 am »
I have got a complex task. Before I start to code, maybe someone has an advice on how to do this:

- via the ZoomDragTool you can click into the chart and draw a rectangle
- my task is to provide the same rectangle drawing method but to select chart data:

For example I have 5 series in a chart, the user draws a rectangle in the chart. Then a dialog pops up to select a series. The user says e.g. to take series number 4. Then all data of series 4 that is within the drawn rectangle is taken and exported as text file/list etc. The aim is that the user gets statistics for the selected range - mean, standard deviation, maximum, minimum.

What do you propose or does anyone knows maybe a forum thread where a users had a similar problem?

The approach I have in mind is this one:
1. user presses a button "select chart section"
2. the user clicks twice, I take the xy-coordinates of the clicks and draw a visible rectangle into the chart (I hope this is possible somehow)
3. a dialog pops up to select the series that should be used
4. a second dialog pops up showing the statistical data of the selected series withing the selection rectangle
« Last Edit: July 04, 2021, 11:40:58 pm by Muso »

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #1 on: June 21, 2021, 11:16:05 am »
The one Charttool which gets closest to your requirements is the TDataPointDistance tool. It does not only measure distances but can be used for any calculation for the datapoints between two mouse-selected end points in its OnMeasure event. It does not draw a rectangle, though, but it should be possible to add it. I used it in my corona program (https://github.com/wp-xyz/corona/tree/master/source) to fit an exponential function to the increasing or decaying case counts (unit cTimeSeriesFrame). The same idea is applied (in a probably simpler way) in the distancedemo, page "Fit", which is in folder components/tachart/demo/distance of your Lazarus installation.

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #2 on: June 21, 2021, 12:53:07 pm »
In the attachment I am showing you a different solution based on 4 constant lines for the limitations of the measurement rectangle, a DataPointDragTool (to drag each constant line) and a TUserDefinedChartTool (to drag a rectangle of the chart where the constant lines follow this rectangle). Each movement of a rectangle triggers the calculation of the statistics for the points enclosed by the constant lines.
« Last Edit: June 21, 2021, 03:01:28 pm by wp »

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #3 on: June 21, 2021, 01:51:02 pm »
In the attachment I am showing you a different solution based on 4 constant lines for the limitations of the measurement rectangle, a DataPointDragTool (to drag each constant line) and a TUserDefinedChartTool (to drag a rectangle of the chart where the constant lines follow this rectangle). Each movement of a rectangle triggers the calculation of the statistics for the points enclosed by the constant lines.

Many thanks for your quick replies! This sounds very promising. I got now the sources of your COVID tool but for your other proposal I cannot see the attachment. Can you please post it again?

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #4 on: June 21, 2021, 03:02:12 pm »
Sorry, I forgot to add it. The zipped project now is attached to the post where it is mentioned.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #5 on: June 21, 2021, 04:29:28 pm »
Sorry, I forgot to add it. The zipped project now is attached to the post where it is mentioned.

Amazing! That is what I was looking for.

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #6 on: June 22, 2021, 12:17:47 am »
I am attaching an extended version of the demo. It contains a ChartListbox enumerating the data series of the chart. The selected series is analyzed, you can select several series by SHIFT or CTRL-clicking on their name in the listbox.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #7 on: June 22, 2021, 02:24:16 am »
I am attaching an extended version of the demo. It contains a ChartListbox enumerating the data series of the chart. The selected series is analyzed, you can select several series by SHIFT or CTRL-clicking on their name in the listbox.

Even more amazing! This should become an official demo as it is.

I already started coding and understand the necessary code now a bit better now.
Maybe I am too new so I google and search the forum but often some info is simply not yet available. Take for example the event "OnAfterDrawBackWall". The lazaurs IDE has no info about this event and also not the TAChart docs - or I cannot find them. Where can I find this docs or who should/can I inform to document the different chart events?

many thanks for your outstanding help and regards
Uwe

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #8 on: June 22, 2021, 10:19:24 am »
This is the "official" TAChart documentation; it is continuously updated whenever a new feature has been added, but it should be valid for older versions to a very large extent: https://wiki.lazarus.freepascal.org/TAChart_documentation

There is a bunch of tutorials, one of them covering the background drawing events: https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Background_design.

The majority of the TAChart demos coming with Lazarus are listed and briefly explained in https://wiki.lazarus.freepascal.org/TAChart_Demos.

https://wiki.lazarus.freepascal.org/TAChart_Runtime_FAQ addresses how to perform the most important tasks at runtime (work in progress, incomplete).

https://wiki.lazarus.freepascal.org/Comparing_TAChart_with_Delphi's_TeeChart_Standard compares TAChart with TeeChart of Delphi (incomplete).

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #9 on: June 22, 2021, 01:04:37 pm »
This is the "official" TAChart documentation
...
There is a bunch of tutorials

The official documentation is in my bookmarks and I use it frequently. However from a newcomer perspective I often cannot find what I am looking for. My example was the events. So a section "Events" would be helpful. This would list all TAChart's components events and can link to the corresponding tutorial where the events are explained in action. This would also be a nice guide to see what tutorials are good for what purpose.

Moreover, info in the IDE would be nice. For example for the OnMouseWheel event I see in the IDE the attached. This helps a lot to know where to look for further info.

I don't want to complain too much since this forum is amazing in helping  :). To help improving the docs, I could start an Events section in the TAChart docu Wiki page if you allow me that. However, since I don't have much knowledge I can only start with the framework.

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #10 on: June 22, 2021, 08:09:40 pm »
To help improving the docs, I could start an Events section in the TAChart docu Wiki page if you allow me that. However, since I don't have much knowledge I can only start with the framework.
Thanks for the offer, but an empty framework is not much help ;)

I just uploaded an enhanced xml documentation file for TAChart to trunk. It contains the help texts that pop up when you move the mouse over a TAChart identifier, or that appear in the info panel of the object inspector. I added a description for the Chart events. There's still a lot to do, and this is where you could help: Open the FPDoc editor (menu "View"), navigate to a TAChart unit and click into a property for which you want to write documentation. If documentation already exists it will be displayed in the FPDocEditor window. If it does not, click on "Create help item" and fill in the pages, usually "Short", often also "Description", sometimes "SeeAlso". Study the already existing documentation to learn how the format should be. After clicking on the Save button you see the new help text by moving the mouse over the newly documented identifier. Be careful with the xml tags - if there are errors the help file cannot be loaded any more (but the FPDocEditor gives a hint where the error is).

Important: Since the FPDocEditor introduces a lot of formatting changes it is extremely difficult for me to see the text that you added or changed. Therefore it is very important that you only use the file of the trunk version (tagraph.xml or any other, in folder components/tachart/fpdoc of the Lazarus trunk installation).

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #11 on: June 23, 2021, 01:23:52 am »
I just uploaded an enhanced xml documentation file for TAChart to trunk.

Many thanks! This looks good and already helped me.

There's still a lot to do, and this is where you could help:

I will do so. However, as I am I am quite a noob in TAChart. But I stumbled over other missing docs in other elements. So I will document whenever I think I can really explain something.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #12 on: June 25, 2021, 02:29:46 pm »
I have two questions regarding your example:

- I have several series and some are not active. How can I achieve that the non-active series don't appear in the TChartListbox?

- I have several series and some are not active. Therefore they don't appear in the legend. But when I now start the data selection mode they all appear in the legend. When I leave the selection mode the legend looks fine again. So how can i keep the legend untouched while being in selection mode.


Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: selecting chart data like with the Zoom Drag Tool
« Reply #13 on: June 25, 2021, 02:35:16 pm »
I have a third question:

- your solution allows to drag the TConstantLines. The problem is that the user is not aware of that feature. So what I want is that when the mouse is over a TConstantLine, the cursor changes to crSizeNS or crSizeWE, respectively. Is that possible?

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: selecting chart data like with the Zoom Drag Tool
« Reply #14 on: June 25, 2021, 03:30:06 pm »
- I have several series and some are not active. How can I achieve that the non-active series don't appear in the TChartListbox?
My example abuses the ChartListBox to some extent because normally there are checkboxes by which the series can be shown and hidden, and I removed the checkboxes (cloShowCheckboxes in Options) because showing/hiding in the ChartListbox screws up the logic of the example.

The TChartListbox has an event OnAddSeries in which you can set the boolean argument ASkip to true to prevent adding a series. In my example this is already used to remove the constant lines from the ChartListBox

- I have several series and some are not active. Therefore they don't appear in the legend. But when I now start the data selection mode they all appear in the legend. When I leave the selection mode the legend looks fine again. So how can i keep the legend untouched while being in selection mode.
I don't know what you are doing. Please try to reduce your project to a minimum level and post it here.

- your solution allows to drag the TConstantLines. The problem is that the user is not aware of that feature. So what I want is that when the mouse is over a TConstantLine, the cursor changes to crSizeNS or crSizeWE, respectively. Is that possible?
I know of this limitation, but don't see a simple way to fix it (I myself did not write this part of TAChart).

 

TinyPortal © 2005-2018