A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
Krac
- Posts: 17
- Joined: Thu Dec 07, 2006 2:26 pm
- Location: Baia Mare, Romania
Post
by Krac » Fri Jan 26, 2007 10:40 am
Hello everybody
Is it possible to change the label of a desired item within a spider-web chart legend?
I went so far and got a LegendItemCollection and also the individual LegendItem(s) for the collection, but there is no setLabel method implemented!
So how can this be done?
For BarChart, I have overriden the StandardCategorySeriesLabelGenerator into a CustomizedCategorySeriesLabelGenerator and performed a
renderer.setLegendItemLabelGenerator with the new CustomizedCategorySeriesLabelGenerator... everything worked just smoothly.
TIA
-
Krac
- Posts: 17
- Joined: Thu Dec 07, 2006 2:26 pm
- Location: Baia Mare, Romania
Post
by Krac » Mon Jan 29, 2007 10:49 am
After more study, I have found useful to override the getLegendItems() method of the SpiderWebPlot class, as follows:
Code: Select all
public LegendItemCollection getLegendItems()
{
LegendItemCollection result = new LegendItemCollection();
java.util.List keys = null;
if (this.getDataExtractOrder() == TableOrder.BY_ROW) {
keys = this.getDataset().getRowKeys();
}
else if (this.getDataExtractOrder() == TableOrder.BY_COLUMN) {
keys = this.getDataset().getColumnKeys();
}
if (keys != null) {
int series = 0;
Iterator iterator = keys.iterator();
Shape shape = getLegendItemShape();
while (iterator.hasNext()) {
String label = iterator.next().toString(); // original label
label = CustomFunction4Label(); // new custom label
String description = label;
Paint paint = getSeriesPaint(series);
Paint outlinePaint = getSeriesOutlinePaint(series);
Stroke stroke = getSeriesOutlineStroke(series);
LegendItem item = new LegendItem(label, description,
null, null, shape, paint, stroke, outlinePaint);
result.add(item);
series++;
}
}
return result;
}
Anyhow, I would have found it more easy to just have a method setLabel() for the LegendItem class...