ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Hoto add custom hotspot data to custom legend entries?
Posted by Michael P. on Feb-10-2022 18:11
Hi there,
for various line layers we are adding custom legend entries via the legendBox->addKey function. Those visible legend strings are NOT the same as the datasetnames of the line layers, they may be totally custom.

So how can I add some additional identifier to such a legend key in order to identify which line layer corresponds to it when I check the image map hotspot (imap_handler->getHotSpot) on mouse click?

Qt 5.9, Chartviewer 6.3

best regards,
Michael

  Re: Hoto add custom hotspot data to custom legend entries?
Posted by Peter Kwan on Feb-11-2022 03:59
Hi Michael,

You probably already know that when your create an image for the legend box (using LegendBox.getHTMLImageMap) to make it clickable, the "dataSetName" will be the text you put into the legend entry. So you can get back the text. My understanding is that your code is unable to identify which line is the entry for, because the legend text can have no relationship to the "dataSetName" of the line.

One method to solve the problem is to create a map that maps the legend text to the dataSetName of the line. For example, you can create a:

std::map<std::string, std::string> myMap;

When you add the legend text, you also add an entry:

myMap[std::string(myLegendText)] = std::string(myLineDataSetName);

When the user clicks on something, you can check if there is a mapping available to map to the actual line dataSetName. This method works as long as the legend entries have unique text.


Another method is to add the custom legend key by adding a dummy layer that displays nothing other than filling the legend box. An example is:

// Layer with empty arrays to add legend entries only
LineLayer *layer2 = c->addLineLayer();
layer->addDataSet(DoubleArray(), 0xff00ff, "Some Custom Text");
layer->addDataSet(DoubleArray(), 0xffff00, "ABCD EFGH");

// Add an extra array to represent the actual names for these legend entries
const char* actualNames[] = {"My Actual Name", "efgh abcd"};
layer->addExtraField(StringArray(actualNames, 2));


Then the legend box image map can be obtained using:

const char *myLegendBoxImageMap = c->getLegend()->getHTMLImageMap("clickable?name={dsField0}");

In this way, for the legend box, the "dataSetName" still refers to the legend text, while the "name" attribute will refer to the actual names.

Hope this can help.

Regards
Peter Kwan

  Re: Hoto add custom hotspot data to custom legend entries?
Posted by Michael P. on Feb-11-2022 21:56
Hi, thanks for the solutions.
Number two is more usable as the legend entries may not be unique etc.

BR Michael