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

Message ListMessage List     Post MessagePost Message

  A Legend to a Percentage Bar Chart
Posted by Victoria on Sep-03-2019 21:13
Hi Peter,
I would like to create a Percentage Bar Chart with a legend. For creating of a Bar Chart I use the following code:
BarLayer *layer;
for (int j=0; j<anzahlDatensaetze; j++)
{ layer->addDataSet(DoubleArray(datensaetze[j], dataLaenge),
multiColor [j],vecDataLabels[j].getLabel());}
Also I am needing a legendBox. And there is a problem there:
I'd like a legendBox as follows:
LegendBox *legendBox = barchart->addLegend(..);
legendBox ->setText("<*block,valign=top*><*advanceTo=10*><*block,width=70*>{label}<*/*><*block,width=40,halign=right*>{percent}<*/*>%");
It works in Pie Chart, but it seems not working in a Percentage Bar Chart.
What could I do? If I have to use the function legendBox ->addKey(..), then I will have to calculate the percent Value myself.

  Re: A Legend to a Percentage Bar Chart
Posted by Peter Kwan on Sep-04-2019 12:53
Hi Victoria,

It is not clear what does "percentage" mean for a legend icon. In any case, you would need to compute the "percentage" yourself.

In ChartDirector, the {percent} applies to a single value. It computes the percentage of the single value relative to the sum of a "collection" of values. The "collection" is all values at the same x-coordinate as the single value. For example, in a bar layer, the single value is compared with all the values on the same bar. There is also another kind of percentage "{gpercent}" in which the "collection" is defined differently. In any case, the percentage is a "single value" compared with the "collection".

For a legend icon, it does not represent a single value, but a collection. For example, consider the "Percentage Bar Chart" sample code:

https://www.advsofteng.com/doc/cdcpp.htm#percentbar.htm

The "Hardware" icon represents the hardware dataset, which has 5 values. That is why there is no {percent} or {value} defined for the legend icon.

Regards
Peter Kwan