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.