Synchronisation of crosshairs

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Rudi23
Posts: 7
Joined: Tue Nov 06, 2007 10:00 am

Synchronisation of crosshairs

Post by Rudi23 » Mon Nov 19, 2007 5:52 pm

Hello,

I hava two JFreeCharts in a SWT-Composite and I would like to synchronize the vertical crosshairs. So when I click the upper chart, I have to move the crosshair in the lower and contrariwise. I found the appropriate methods in the classes to get and set the crosshairvalues. The problem is, that my solution works just in one direction. So, clicking in the upper chart first, it works as far I don't leave the first chart. When I click in the second, the crosshairs are out of sync. It works also for the second chart, as long as I start clicking in the second chart and don't change to the first. Coul't you please give a look to my solution:

boolean lock1 = false;
boolean lock2 = false;

private class MyChartListener1 implements IChartListener{

public void valueSelected(ISample sample) {


if(chart2 == null || lock1)
return;

XYPlot plot1 = (XYPlot)chart1.getPlot();
XYPlot plot2 = (XYPlot)chart2.getPlot();

int value = (int) plot1.getDomainCrosshairValue();


lock1 = true;
plot2.setDomainCrosshairValue(value, false);

secondChartComposite.forceRedraw();
}


}




private class MyChartListener2 implements IChartListener{

public void valueSelected(ISample sample) {


if(chart1 == null || lock2)
return;

XYPlot plot1 = (XYPlot)chart1.getPlot();
XYPlot plot2 = (XYPlot)chart2.getPlot();

int value = (int) plot2.getDomainCrosshairValue();


lock2 = true;
plot1.setDomainCrosshairValue(value, false);

firstChartComposite.forceRedraw();
}


}

Thank you in advance,
Rudi

Rudi23
Posts: 7
Joined: Tue Nov 06, 2007 10:00 am

Post by Rudi23 » Wed Nov 21, 2007 4:37 pm

Hi all,

I'm still brooding on this problem. If someone has an idea, please let me know :lol:

thanks a lot,
Rudi

Locked