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

Message ListMessage List     Post MessagePost Message

  Questions about legend entry font, hotspot and label format.
Posted by jettaime on Aug-10-2012 19:34
Attachments:
Hi,

I'm using the ChartDirector version 5.1 for C++.
Please look at the screenshot image.

'A' : I'd like to make clickable hotspot only the icon of legend entry.

'B' : How can I ensure that the last label should be displayed as supplied format using setMultiFormat?
Axis.setMultiFormat(int filter1, const char *format1, int filter2, const char *format2, int labelSpan = 1, bool promoteFirst = true);

'C' : Is it possible to change font from a specific entry of legend box?


Thank you.
legend_last-label.png

  Re: Questions about legend entry font, hotspot and label format.
Posted by jettaime on Aug-10-2012 19:40
I would change the question about 'A' and 'C'.

The legend entry should have a clickable hotspot on the icon and text.

The new question is how can I distinguish the click event between the icon('A') and text('C').

Thank you.

  Re: Questions about legend entry font, hotspot and label format.
Posted by Peter Kwan on Aug-11-2012 02:08
Hi jettaime,

For distinguishing the icon and the text, in the click event, one of the attributes available from the ImageMapHandler is the bounds of the hot spot (the "coords" attribute). For legend entries, the coords should be a text string in the form xxx,yyy,aaa,bbb, where (xxx, yyy) is the top left corner of the bounding rectangle in pixel coordinates relative to the chart, and (aaa, bbb) is the bottom right corner. You may check if the mouse coordinates is close (say within 15 pixels) to the xxx to determine if it is on the icon side, or on the text side. If you are using ChartDirector Ver 5.1, you may use CChartViewer.getChartMouseX to obtain the mouse x-pixel-coordinates relative to the chart, otherwise you may obtain the coordinates using various Windows API.

For "ensure that the last label should be displayed ...", it depends on who determines the labels on the x-axis in the first place. If the labels are directly specified by your code (eg. using Axis.setLabels or Axis.setLabels2), then the last label is not displayed probably because your code inform ChartDirector not to display that label (eg. by using various filters or setLabelStep). In this case, you may add a particular label back by using Axis.addMark. The label can be formatted using BaseChart.formatValue, and using the same format string you use in setMultiFormat.

Hope this can help.

Regards
Peter Kwan

  Re: Questions about legend entry font, hotspot and label format.
Posted by jettaime on Aug-11-2012 08:37
Thank you for your help.

Could you help me for the third question,
How can I change the font(color, size or style for example bold,italic,...) of specific legend box entry?

Thank you.

  Re: Questions about legend entry font, hotspot and label format.
Posted by Peter Kwan on Aug-12-2012 11:40
Hi jettamine,

The text in the legend entry comes with the name when you add the data set or the layer. To change the font, one of the methods is to include "CDML" mark ups in the name. For example, instead of using "ABC", you may use "<*font=arialbd.ttf,color=cc0000*>ABC". You may look up for "CDML" from the ChartDirector documentation index for the detail syntax.

Hope this can help.

Regards
Peter Kwan

  Re: Questions about legend entry font, hotspot and label format.
Posted by jettaime on Aug-17-2012 12:26
const char* layer_name = "mylayer";
char dataset_name[100];

if(selected)
{
_snprintf_s(dataset_name, _countof(dataset_name), _TRUNCATE, "<*font=arialbd.ttf,color=00646464*>%s", layer_name);
}
else
{
_snprintf_s(dataset_name, _countof(dataset_name), _TRUNCATE, "%s", layer_name);
}

pAreaLayer->addDataSet(MAX_DATA_POINT_COUNT, dataset, -1, dataset_name);
LegendBox *pLegend = c->addLegend(lx, ly, true, "gulim.ttc;arial.ttf;mingliu.ttc", 8.0);
img_map.append(pLegend->getHTMLImageMap("legend","","title='{dataSetName}'", x, y));
// ....

I changed a paticular legend entry's font like above codes.
Although it worked well, the tooltip of CDML-applied legend entry was displayed like "<*font=arialbd.ttf,color=00646464*>" because it was contained int the dataset name.

How can I display only the real-dataset,in this case 'mylayer' name when the CDML applied in legend entry?

Thank you.

  Re: Questions about legend entry font, hotspot and label format.
Posted by Peter Kwan on Aug-18-2012 00:51
Hi jettaime,

For your case, I suggest to simply filter the image map to remove all <* .... *> before using it. The filtering code may be something like (note: I have not tested the code myself):


char *buffer = (char *)(pLegend->getHTMLImageMap("legend","","title='{dataSetName}'", x, y));

char *dest = buffer;
for (char *ptr = buffer; *ptr != 0;) {
    //skip <* .... *>
    if ((*ptr == '<') && (*(ptr + 1) == '*')) {
        ptr += 2;
        while ((*ptr != 0) && ((*(ptr - 1) != '>') || (*(ptr - 2) != '*')))
            ++ptr;
    }
    else
        *(dest++) = *(ptr++);
}
*dest = 0;

img_map.append(buffer);


Regards
Peter Kwan