Recent

Author Topic: tchart selectable series  (Read 3862 times)

jitoncio

  • Newbie
  • Posts: 3
tchart selectable series
« on: April 18, 2017, 03:04:40 pm »
Hi,

I have a doubt when looking at some aspects of series and chart. I would like to know how to select a series (TLineseries, TAareaSeries) in a Tchart. Is it possible to use the onclick event on series?

thanks for your help.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: tchart selectable series
« Reply #1 on: April 18, 2017, 03:14:30 pm »
You cannot "select" a series in the same way as e.g. in Excel such that the series is marked by grabber points. But depending on what you want to achieve probably the TChartTools can help you. Look at http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Chart_Tools (chapter 7). But the tutorial covers a only a small fraction of the possibilities, and recently some extension have been added to the datapoint tools.

Or you could use a TChartListbox to select a series.

Please describe what you want to do with the selected series.

jitoncio

  • Newbie
  • Posts: 3
Re: tchart selectable series
« Reply #2 on: April 18, 2017, 03:36:11 pm »
Ok, thanks wp.

What I want to do with the series is that once you have selected you can delete or open a form.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: tchart selectable series
« Reply #3 on: April 18, 2017, 04:15:01 pm »
So, you want to click on a series, and then do something related to the clicked series? For example to change the series color in a color selector form?

There are two ways: TDataPointClickTool and TChartListbox

(1) TDatapointClickTool
  • Add a TChartToolset component. Double-click it and add a DatapointClick tool.
  • Link the Charttoolset to the property Tools of the chart
  • In the DatapointClickTool set Shift to ssLeft (or whatever - this is the key to activate the tool)
  • Add an event handler for the OnDataPointClick event. Cast the tool passed as a parameter to a TDataPointClicktool and you have access to the clicked series: TDatapointClickTool(ATool).Series
NOTE: At the moment, the tool reacts only on clicks near the data points, not on the conntecting lines of LineSeries, and not within the filled area of an AreaSeries. Use the tool's GrabRadius to increase the tolerance of missing a data point.

(2) TChartListbox
  • Add a TChartListbox component
  • Link its property Chart to the chart --> all the series of the chart appear with symbols in the listbox.
  • Add an event handler for OnSeriesIconDblClick. This event fires when the user double-clicks on the icon of the series in the listbox. Use the provided index to access the series of the clicked icon: ChartListbox.Series[AIndex].
As an example have a look at attached project. Here the DatapointClickTool and the double-click of the series icon in the listbox open a colordialog for changing the series color.

For further control of the series appearance you might be interested to know that the TAChart of Lazarus trunk contains a new TChartCombobox for selecting pointer styles, line styles, line widths and brush styles.

jitoncio

  • Newbie
  • Posts: 3
Re: tchart selectable series
« Reply #4 on: April 18, 2017, 05:52:27 pm »
Great wp. thanks for the explanation. Is very clear and I understand.

I will try both options and vere is the one that most adapts to the project.

Thank you.

 

TinyPortal © 2005-2018