|
How can I have a legend with just some entries |
Posted by David Thielen on Feb-23-2021 05:39 |
|
Hi;
I want to have a legend with just some entries (not the grey columns in the below example). Do I do this with addKey()?
And if so, is there an example somewhere?
Also, do I need to first clear out the defaults? Or does that happen on the first addKey() call?
thanks - dave
|
Re: How can I have a legend with just some entries |
Posted by Peter Kwan on Feb-23-2021 11:49 |
|
Hi David,
If your data set has no name, it will not have automatic legend entry. For example:
// This will have a legend entry
BarLayer layer = c.addBarLayer(data, 0x6699cc, "My DataSet");
// This will have not have a legend entry since there is no text to display
LineLayer layer2 = c.addLineLayer(data, 0xff6600);
If you must provide a name to the data set, but does not want the legend entry, you would like to disable it using:
layer.setLegendOrder(Chart.NoLegend);
See:
https://www.advsofteng.com/doc/cdnet.htm#Layer.setLegendOrder.htm
The LegendBox.addKey can be used to add legend entries to the legend box. It will not remove the automatic entries.
The following is an example that uses LegendBox.addKey:
https://www.advsofteng.com/doc/cdnet.htm#contourlegend.htm
Due to compatibility with some very early versions of ChartDirector, by default, the legend icon of all entries will be a square. To use line style icons, you need to add the line:
LegendBox b = c.getLegend();
b.setLineStyleKey(true);
With setLineStyleKey, lines will use line icons. Other layer types will use the icons appropriate for them (box icons for bar/area, symbols for scatter layers, etc). To add a line style icon, just provide a non-zero line width in LegendBox.addKey:
b.addKey("ABC", 0x336699, 2);
ChartDirector will try to keep all icons the same width. This ensures the text for different icon types will align properly for vertical legend boxes.
Regards
Peter Kwan |
|