Hello
I have a bar chart displaying five products and their market share.
Below the bars there is the legend with the product names (in black).
How can I change the color of the product names and the font size?
I searched the documentation and developer guide and couldn't find an easy solution.
Maybe I've just overlooked it.
Claus
How to change font of legend in bar chart?
-
- Posts: 7
- Joined: Sat Sep 01, 2007 4:19 pm
change legend font size and style
create a legend object as shown
StandardLegend legend = (StandardLegend) chart.getLegend();
and create a font object as shown
Font nwfont=new Font("Arial",0,7);
and assign it to legend obj and add ito chart as shown
legend.setItemFont(nwfont);
chart.setLegend(legend);
the complete code below
StandardLegend legend = (StandardLegend) chart.getLegend();
Font nwfont=new Font("Arial",0,7);
legend.setItemFont(nwfont);
chart.setLegend(legend);
StandardLegend legend = (StandardLegend) chart.getLegend();
and create a font object as shown
Font nwfont=new Font("Arial",0,7);
and assign it to legend obj and add ito chart as shown
legend.setItemFont(nwfont);
chart.setLegend(legend);
the complete code below
StandardLegend legend = (StandardLegend) chart.getLegend();
Font nwfont=new Font("Arial",0,7);
legend.setItemFont(nwfont);
chart.setLegend(legend);
kruthin
hi kruthin,
there isn't the class StandardLegend. I can not found it in API.
I use the following code:
It appears NullPointerException. Do you know why?
there isn't the class StandardLegend. I can not found it in API.
I use the following code:
Code: Select all
LegendTitle legend = chart.getLegend();
Font labelFont = new Font("Arial", Font.BOLD, 12);
legend.setItemFont(labelFont);
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
NullPointerExceptions are usually pretty easy to track down - does the full stack trace give you a line number and a source file name?samtuen wrote:It appears NullPointerException. Do you know why?
If I had to guess (and I do, because you didn't give enough information) I'd say that the getLegend() method is returning 'null' because you created a chart with no legend.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Unable to change the legend font on a bar chart
Hi,
I am using jfreechart to create a bar chart. I am unable to change the font of the legend though. This is my code:
LegendTitle legend = new LegendTitle(plot);
Font font = new Font("Arial",0,12);
legend.setItemFont(font);
legend.setPosition(RectangleEdge.BOTTOM);
chart.addLegend(legend);
I looked under jre/lib/fonts and used the fonts that are in that directory and that didn't seem to work either. Is there anything wrong with the code, or is there any thing else I have to do like installing the fonts etc,..? thanks!
I am using jfreechart to create a bar chart. I am unable to change the font of the legend though. This is my code:
LegendTitle legend = new LegendTitle(plot);
Font font = new Font("Arial",0,12);
legend.setItemFont(font);
legend.setPosition(RectangleEdge.BOTTOM);
chart.addLegend(legend);
I looked under jre/lib/fonts and used the fonts that are in that directory and that didn't seem to work either. Is there anything wrong with the code, or is there any thing else I have to do like installing the fonts etc,..? thanks!
Hi david,
you're right. Thank you!
Hi leyla,
try to change
you're right. Thank you!
Hi leyla,
try to change
Code: Select all
LegendTitle legend = new LegendTitle(plot.getRenderer());