Copy of a chart : problem of refreshing ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Zanton
Posts: 9
Joined: Thu Jul 13, 2006 1:14 pm

Copy of a chart : problem of refreshing ?

Post by Zanton » Mon Jul 31, 2006 12:33 pm

Here is my problem : I have a JTabbedPane with two tabs which have the same structure : a Jtable and under a JFreeChart (from XYDataset). The JTable are different but I'd like to have the same chart on the two tabs.
I implemented the Cloneable interface to do it, and I have my chart on both tabs, but there's something strange : the event on the second chart doesn't work. For example, if I try to select a rectangular zone for zooming on the chart on the second tab, the selection rectangle still stays but nothing happens. If I go on the first chart, the zoom has be done on it. If I go back to the second chart, the chart has been updated and the zoom is correct. If I first zoom on the first chart, and then I go to the second tab, the zoom has been done too.

It seems to me there must be a problem of refreshing the chart, but I'm very surprised with the zoom or right click function not working at first on the second chart, but working if I go to first tab and then back to the second.

Thanks for helping.

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 » Mon Jul 31, 2006 4:14 pm

Have you cloned the JFreeChart instance? Or the ChartPanel? It sounds like you've found a bug, so if you give me some more hints about how to reproduce it, I'll track it down.
David Gilbert
JFreeChart Project Leader

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

Zanton
Posts: 9
Joined: Thu Jul 13, 2006 1:14 pm

Post by Zanton » Tue Aug 01, 2006 9:15 am

In fact, I put the chart in a JPanel and I'm cloning this JPanel. I have to say I'm not sure I perfectly cloned the JPanel. I show you the concerned part of the code :

Code: Select all

public class WinSDF  extends JPanel implements Cloneable	{

	private XYDataset data = GenerateSDF.createDataset();
	private static int num;
	private GraphieSDF chart;
	private ChartPanel panel;
	protected static JFreeChart graphie1;

	public WinSDF()
	{
		chart = new GraphieSDF();
		graphie1 = chart.createPointChart(data);
		panel = new ChartPanel(graphie1, true, true, true, true, true);

        panel.setPreferredSize(new java.awt.Dimension(500, 400));

        panel.addChartMouseListener(new ChartMouseListener(){
        	...
		        }

			public void chartMouseMoved(ChartMouseEvent event) {
                        ...
		        } 
        });

		this.add(panel);
		this.setEnabled(true);
	}
	@Override

	   protected Object clone() throws CloneNotSupportedException {

	      WinSDF clone = (WinSDF) super.clone();
	      clone.data = this.data;
	      clone.chart = this.chart;
	      clone.graphie1 = this.graphie1;
	      clone.panel = this.panel;
	      
	      panel.addChartMouseListener(new ChartMouseListener(){
                    ...
	        });
	
			this.add(panel);
			this.setEnabled(true);

	      return clone;
	   }

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 » Tue Aug 01, 2006 9:52 am

Any reason why graphie1 is static?
David Gilbert
JFreeChart Project Leader

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

Zanton
Posts: 9
Joined: Thu Jul 13, 2006 1:14 pm

Post by Zanton » Tue Aug 01, 2006 10:43 am

It is used in a static method of the class.

Edit: I just tried not making it static, but it doesn't change anything.

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 » Tue Aug 01, 2006 10:46 am

But you know that a static field is shared by all instances of the same class, right? So this could be the problem with your cloning.
David Gilbert
JFreeChart Project Leader

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

Zanton
Posts: 9
Joined: Thu Jul 13, 2006 1:14 pm

Post by Zanton » Tue Aug 01, 2006 10:49 am

Yes I do :) I just edited my previous post to tell you it doesn't change anything graphie1 being static or not.

Locked