Customize legend?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
hhenrion
Posts: 12
Joined: Fri Mar 07, 2008 9:56 am

Customize legend?

Post by hhenrion » Mon Mar 31, 2008 9:50 am

Hi,

Is it possible to add a part to a legend?

In fact, I want my legend to be composed of one or many words, and after, my "normal" legend.

I have many item and want to gain some place. It is important for my work!

I want for instance to do that :
"presentation 1 : ° presentation 2 : ° presentation 3 : °"
become -->
"presentation : 1 : ° 2 : ° 3 : °"


Thank you!

deepujain
Posts: 21
Joined: Sat Jun 02, 2007 10:52 am
Location: Bangalore

Post by deepujain » Mon Mar 31, 2008 9:56 am

Yes its possible to customize legends. First you need to remove the existing legends from the chart using the following piece of code.
//Remove all the legends from chart.
for(int i=0;i<mycollection.getItemCount();i++){
chart.removeLegend();
}

Now create
LegendItemSource mysource= new MyLegendSource(mycollection);
LegendTitle legend= new LegendTitle(mysource);//,(Arrangement)HorizontalAlignment.CENTER,(Arrangement)VerticalAlignment.BOTTOM);
legend.setPosition(RectangleEdge.BOTTOM);
legend.setBackgroundPaint((Paint)ChartColor.WHITE);
legend.setBorder(new BlockBorder());
Add this new legend to your chart
chart.addLegend(legend);
Zzzzz....

hhenrion
Posts: 12
Joined: Fri Mar 07, 2008 9:56 am

Post by hhenrion » Mon Mar 31, 2008 10:03 am

Thanks for your answer.
I already have tried that :

Code: Select all

		jfreechart = ChartFactory.createXYLineChart("", "", "", (XYDataset)ds, PlotOrientation.VERTICAL, false, true, false); 
		LegendTitle legend = new LegendTitle(jfreechart.getPlot());
		legend.setItemFont(new Font(null,Font.PLAIN,10));
		legend.setPosition(RectangleEdge.BOTTOM);
		legend.setBorder(1,	1, 1, 1);
		jfreechart.addLegend(legend);
But I want to customize the content of my legend...
And I still don't know how to do what I have explain up.

Locked