|
Clickable labels? I'm sure it's possible, just cannot find an example. |
Posted by Tony on Oct-24-2021 02:34 |
|
As the subject says, can I get a notification if a label is clicked?
Thanks in advance,
Tony. |
Re: Clickable labels? I'm sure it's possible, just cannot find an example. |
Posted by Peter Kwan on Oct-24-2021 12:20 |
|
Hi Tony,
Yes, it is possible.
You probably already know that "data objects" (objects that represents data values, such as bars in bar chart, sectors in pie chart, line segments in line chart, etc.) are clickable by using an image map (created using BaseChart.getHTMLImageMap). To make other objects clickable, if you can determine the position and size of the object, you can create an image map for that object and append it to the data object image map. (An image map is just a text string.)
For your case, the exact code depends on what type of label you are referring to. For axis labels, there is already an Axis.getHTMLImageMap for them. For legend box items, there is LegendBox.getHTMLImageMap. For a custom label added using BaseChart.addText, you can use Box.getImageCoor to get its position and size in HTML compatible format, and generate the image maps. It is like:
// The label image map. You can put some parameters in href. In the click event handler,
// you can detect these parameters to determine which object is being clicked.
char labelImageMap[10000];
sprintf(labelImageMap, "<area %s href='aaa?bbb=1&ccc=2' title='you can put tooltip here'>", myTextBox->getImageCoor());
As a reference, you may refer to the following page to see what an image map looks like for the data objects generated by ChartDirector.
https://www.advsofteng.com/doc/cdcpp.htm#BaseChart.getHTMLImageMap.htm
To append the image maps, it is like:
// data object map
std::string imageMap = c->getHTMLImageMap(....);
// append the labelImageMap
imageMap += labelImageMap;
// ... append other image maps if necessary ...
// Set the image map to the viewer
myChartViewer->setImageMap(imageMap.c_str());
Regards
Peter Kwan |
Re: Clickable labels? I'm sure it's possible, just cannot find an example. |
Posted by Tony on Oct-25-2021 16:10 |
|
I'm having a lot of trouble getting this working, nothing I try seems to pick up the clicks. I can get the clicks fine from when a series is clicked, just not the legend box.
Really simple code,
LegendBox* legendBox = c->addLegend(nLegendAreaX, nLegendAreaY, false, "arialbi.ttf", 9.0 * scale);
// Add entries to the legend box
legendBox->addKey("95% Line Confidence", 0x806666ff);
legendBox->addKey("95% Point Confidence", 0x8066ff66);
std::string strLegendBoxHTMLImageMap = legendBox->getHTMLImageMap("TEST legend", "qf", "title");
wxString strChartImageMap = c->getHTMLImageMap("") + strLegendBoxHTMLImageMap;
setImageMap(strChartImageMap);
Does this look right? I'm modifying a sample in the ChartDirector library.
Thanks in advance,
Tony. |
Re: Clickable labels? I'm sure it's possible, just cannot find an example. |
Posted by Tony on Oct-25-2021 16:15 |
|
Ignore me. I've checked the documentation (and read it properly rather than just skimmed), and noticed "This method should be called only after creating the chart image".
It works now.
Many thanks,
Tony. |
|