Where is class 'Legend'

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rong_bo
Posts: 3
Joined: Fri May 06, 2016 4:13 am
antibot: No, of course not.

Where is class 'Legend'

Post by rong_bo » Mon May 09, 2016 6:56 am

Actually this problem is from another issue (viewtopic.php?f=3&t=117569), and compiler said no class 'Legend' when trying to uprade an some old codes.

Here is the code,

Code: Select all

JFreeChart chart = ChartFactory.createPieChart3D(
		"", //Title
		pieDataset, //Dataset
		false, //Show legend
		true, //Use tooltips
		false //Configure chart to generate URLs?
		);
// set legend here
Legend legend= Legend.createInstance(chart);
chart.setLegend(legend);
legend.setAnchor(Legend.EAST);
 
Can anybody tell me how to upgrade this code?

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Where is class 'Legend'

Post by John Matthews » Mon May 09, 2016 11:55 am

The factory method shown passes your legend request on to the relevant JFreeChart constructor. Either change the request to true, for the default location, or create your own factory having a LegendTitle with a different RectangleEdge, for example:

Code: Select all

legend.setPosition(RectangleEdge.RIGHT);

rong_bo
Posts: 3
Joined: Fri May 06, 2016 4:13 am
antibot: No, of course not.

Re: Where is class 'Legend'

Post by rong_bo » Tue May 10, 2016 3:37 am

Thanks for your reply,

These are old codes and use jfreechart 1.0.0 pre2, and I want to upgrade to latest version, but I cannot find the class 'Legend' in current jfreechart, so this class has been removed from jfreechart?

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

Re: Where is class 'Legend'

Post by david.gilbert » Tue May 10, 2016 6:05 am

At some point the legend code was changed to fit into the chart title / subtitle layout mechanism, so the class is now LegendTitle. The API is not the same, so your existing code (which must be very old) won't map that well.
David Gilbert
JFreeChart Project Leader

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

Locked