|
Legend |
Posted by Raimund on Jul-20-2023 14:44 |
|
Is there a simple way to integrate checkboxes in a legend, e.g. to show or hide individual elements from the plot by clicking on them? |
Re: Legend |
Posted by Peter Kwan on Jul-21-2023 12:28 |
|
Hi Raimund,
There are several ways to show/hide elements from the plot by clicking. The simplest way is to add some checkboxes to your user interface. An example is (I assume you are using MFC/C++):
https://www.advsofteng.com/doc/cdcpp.htm#zoomscrolltrack2.htm
When the user clicks on the checkbox, the code simply redraws the chart. The charting code is designed to add a data series only when the corresponding checkbox is checked.
If you want the checkbox to be "integrated" into the built-in ChartDirector legend key, then you would need to use custom legend keys and draw the checkbox icons with CDML. The following is an example of using custom legend keys:
https://www.advsofteng.com/doc/cdcpp.htm#surfacelinezone.htm
You need to draw the custom legend keys no matter the data is shown or hidden (otherwise the user cannot re-show the data after they are hidden).
In brief:
1. You need to disable to default automatic legend keys by using Layer.setLegendOrder (I assume it is an XYChart) to set the legend mode to Chart::NoLegend. See:
https://www.advsofteng.com/doc/cdcpp.htm#Layer.setLegendOrder.htm
2. You can then add custom legend keys using LegendBox.addKey. On Windows, there is a "Wingdings 2" font that includes the checkbox symbols.
3. Include an image map for the LegendBox so that the legend keys become hot spots.
https://www.advsofteng.com/doc/cdcpp.htm#LegendBox.getHTMLImageMap.htm
4. When the user clicks on the chart, in the click handler, check if the legend key is clicked, and update the hide/show state of the sereis and redraw the chart.
Best Regards
Peter Kwan |
Re: Legend |
Posted by Raimund on Jul-21-2023 15:22 |
|
Hi Peter,
Thank you very much for the help. Your support is really impressive!
Raimund |
|