Hello,
I am using a combined plot. I set tool tips using the custom generator. I then added a chartmouselistener that creates annotations when points on the bottom plot are clicked.
Anyway, I noticed my tool tips stopped appearing after I added the listener. So, then I commented out the add listener. Voila, the tool tips appeared again.
Below is the code: If you see something that is causing this issue or have any suggestions I would appreciate it. Thanks.
CustomXYToolTipGenerator ttg= new CustomXYToolTipGenerator();
---- ttg is filled with tooltips for points on the top plot ----
CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new NumberAxis(Xlabel));
cplot.setGap(1.0);
// add the subplots...
cplot.add(PLOT1, 10);
cplot.add(PLOT2, 1);
cplot.setOrientation(PlotOrientation.VERTICAL);
JFreeChart chartPanel = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, cplot, true);
chartPanel.setTitle(PlotTitle);
plot.getRangeAxis().setAutoRange(true);
plot.getDomainAxis().setAutoRange(true);
PLOT1.getRenderer().setBaseToolTipGenerator(ttg);
ChartListener chartMouseListener = new ChartListener(null);
chartPanel.addChartMouseListener(chartMouseListener);
public class ChartListener implements org.jfree.chart.ChartMouseListener {
XYDataset dataset;
public ChartListener(XYSeriesCollection dataset) {
this.dataset = dataset;
}
public void setDataset(XYDataset indataset) {
this.dataset = indataset;
}
@Override
public void chartMouseClicked(ChartMouseEvent cme) {
if (cme.getEntity() == null) {
return;
}
XYItemEntity xyitem = (XYItemEntity) cme.getEntity();
int i = 0;
if (dataset == xyitem.getDataset()) {
if (xyitem.getSeriesIndex() == 0) {
double x = dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem());
double y = dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem());
XYLineAnnotation a2 = new XYLineAnnotation(x, 0.0, x, Math.abs(y));
if (xy.getTopPlot().getAnnotations().contains(a2)) {
xy.getTopPlot().removeAnnotation(a2);
}
else {
xy.getTopPlot().addAnnotation(a2);
}
}
}// otherwise it is the top plot that was clicked. }
@Override
public void chartMouseMoved(ChartMouseEvent cme) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}