Bar Chart Legend Customization

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Krac
Posts: 17
Joined: Thu Dec 07, 2006 2:26 pm
Location: Baia Mare, Romania

Bar Chart Legend Customization

Post by Krac » Thu Dec 07, 2006 3:18 pm

Hello everybody :-)

Is it possible to change the label of a desired item within a bar chart legend?

TIA

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Dec 07, 2006 5:29 pm

In the renderer, you can specify your own legend item label generator:

Code: Select all

renderer.setLegendItemLabelGenerator(yourGeneratorHere)
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Krac
Posts: 17
Joined: Thu Dec 07, 2006 2:26 pm
Location: Baia Mare, Romania

Post by Krac » Thu Dec 07, 2006 10:35 pm

david.gilbert wrote:In the renderer, you can specify your own legend item label generator:

Code: Select all

renderer.setLegendItemLabelGenerator(yourGeneratorHere)
Thanks for the swift reply, David; a short example on how the custom generator should look like would be very much appreciated. I saw some examples for series items labels customization, but none for Bar Chart Legend items customization.

Thanks again :)

Krac
Posts: 17
Joined: Thu Dec 07, 2006 2:26 pm
Location: Baia Mare, Romania

Post by Krac » Thu Dec 07, 2006 11:53 pm

OK, finally got it working :)
___________________________________________________
static class CustomizedCategorySeriesLabelGenerator extends StandardCategorySeriesLabelGenerator {
private static final long serialVersionUID = 1L;
public CustomizedCategorySeriesLabelGenerator() {
super();
}
@Override
public String generateLabel(CategoryDataset dataset, int series){
switch (series) {
case 0: result = "Series 1"; break;
case 1: result = "Series 2"; break;
case 2: result = "Series 3"; break;
default: result = "Unknown Series";
}
return result;
}
}
___________________________________________________

jfreeuser2006
Posts: 59
Joined: Mon Nov 20, 2006 1:00 pm

Post by jfreeuser2006 » Mon Jan 15, 2007 6:54 am

How about shapes?

Locked