Remove Legend

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
erabard
Posts: 3
Joined: Mon Sep 29, 2008 3:18 pm

Remove Legend

Post by erabard » Mon Sep 29, 2008 3:32 pm

Hi, anyone knows if is possible to remove the legend of a ChartPanel as shown in the picture below?
[img]img174.imageshack.us/my.php?image=plotdn4.jpg[/img]

I've tried to use removeLegend() method but seems doesn't work...
the code is:

Code: Select all

Plot plot=plotGraphData(functiontoplot);
JFreeChart chart = new JFreeChart(plot);
chart.removeLegend();
ChartPanel chartPanel = new ChartPanel(chart);
....
...
...
protected Plot plotGraphData(VectorExpolFunction plotfunction) {
		this.series = new XYSeries("Probability Density Function f(t)");
		try{
			calculateMaxx(plotfunction);
		}
		catch(Exception ex)
		{
			maxx=10;
		}
		for (int i = 0; i <(maxx*10); i++) 
		{     
			 x = 0.1 * i; 
			 y =    LibExpolFunctions.evaluate(x,plotfunction).doubleValue();    
			this.series.add(x, y);
		}
		try{
			calculateMaxy();
			setAxisVariable(plotfunction.get(0).getMin_domain(), maxx, 0, maxy);
		}
		catch(Exception ex)
		{
			setAxisVariable(0, 10, 0, 10);
		}
		data = new XYSeriesCollection(this.series);
		setAxis();
		renderer = new StandardXYItemRenderer();
		plot = new XYPlot(data, domainAxis, rangeAxis, renderer);
		return plot;
Thank's to all
Federico

RugWarrior
Posts: 17
Joined: Wed Jul 30, 2008 11:54 am

Hi :)

Post by RugWarrior » Mon Sep 29, 2008 6:57 pm

Hi Frederico,

please have a look at:

http://www.jfree.org/phpBB2/viewtopic.p ... ght=legend

Perhaps I may be helpful :)

Regards,
Sol

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

Re: Remove Legend

Post by david.gilbert » Mon Sep 29, 2008 7:01 pm

erabard wrote:I've tried to use removeLegend() method but seems doesn't work...
The plot in the image is not created from the code you posted, unless there is some more code that you're not showing us. Please post a *self-contained* demo that we can cut, paste, compile and run.
David Gilbert
JFreeChart Project Leader

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

erabard
Posts: 3
Joined: Mon Sep 29, 2008 3:18 pm

Re: Remove Legend

Post by erabard » Tue Sep 30, 2008 9:01 am

david.gilbert wrote: The plot in the image is not created from the code you posted,
yes, it's created from the code i posted infact initially the value of the function is 0 and so as you can see in the image the plot of the function is a red line in 0.
unless there is some more code that you're not showing us.
yes, but i've resolved!
The problem was that i have another method that replot the graph and in this method i've forgotten to recall removeLegend():

Code: Select all

public void repaintNow(PrimaryEvent comp) {
		if (comp!=null)
		{
			plot=plotGraphData(comp.getVectorexpolfunction());
			chart = new JFreeChart(plot);
			chartPanel.setChart(chart);
			chartPanel.revalidate();
		}
Thank's to all
Federico

Locked