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