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

Message ListMessage List     Post MessagePost Message

  LegendBox template
Posted by Darryl on Jul-28-2011 03:21
I'm probably doing something wrong with the following code, can you help?

I'm using the MFC C++ code version and this is a real-time XY chart with a variable number of line and step line layers.

The legend box entries contain the correct data set name and symbol, but the value is always reported as 0.0 for each entry on each chart update. Is it something wrong with the setText template parameter?

The data points for each layer are, of course, displayed correctly in the chart and their infotips in the image map report their values correctly as well.

This code is called after all layers are created and before the static control's setChart method is invoked:

[...]
// Create a legend box at the top of the chart below the title bar
LegendBox *b = c->addLegend2(55, 33, 4, "arialbd.ttf", 9);

// Set the template of the legend box entries
b->setText("{dataSetName} {value|1}");

// Set the legend text font color to white
b->setFontColor(0xffffff);

// Set the legend background color to Chart::Transparent
b->setBackground(Chart::Transparent, Chart::Transparent);

// Set the width of the legend box to the width of the plot area
b->setWidth(c->getPlotArea()->getWidth());
[....]

I've worked around this by using the default legend box template and creating a text box adjacent to each entry that contains the current value and that works well but it involves getting the image coordinates of each entry and parsing the results to position the boxes, etc.

  Re: LegendBox template
Posted by Peter Kwan on Jul-29-2011 02:04
Hi Darryl,

In a legend box, the {value} is only applicable if the name is associated with a single value. For example, in a pie chart, each sector has a name and is associated with a value. In this case, the {value} refers to the value associated with the name.

For an XYChart, each name is associated with a data series containing multiple values, not a single value. So {value} is not applicable, as it is not sure which value it is referring to.

In the ChartDirector Realtime Chart sample code, the value in the legend box is added by included the value as the name of the data series. The code is like:

//Include the last value as part of the data set name
char buffer[1024];
sprintf(buffer, "Software %.2f", myData[noOfPoints - 1]);
LineLayer *layer0 = c->addLineLayer(DoubleArray(myData, noOfPoints), 0xcc0000, buffer);

Hope this can help.

Regards
Peter Kwan

  Re: LegendBox template
Posted by Darryl on Jul-29-2011 02:11
Thank you Peter.

I suspected that was the case, and I apologize for not examining the example code more closely.

I've adopted a somewhat similar approach by adding an extra field in the layers and referring to that in the legend template. Actually, since there was more info that I wanted to display in the legend, I created two extra fields.

That approach is working well, and I thank you again for a fine produce and excellent support.