Tooltips are out of order when x is duplicate

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Robert Fearn

Tooltips are out of order when x is duplicate

Post by Robert Fearn » Tue Nov 26, 2002 6:09 pm

Hi,
When I add tooltips to a dataseries where the X values are the same, the tooltips are all out of order. If I swap the X and Y so it has duplicate Y values it works fine.
Any ideas why the tooltips gets mixed up for duplicate X values.

I have attached the code to illustrate:

Cheers,
Rob.
PS Big thanks to David Gilbert for all his help

package com.jrefinery.chart.demo;

import java.awt.Insets;
import java.awt.Color;
import java.awt.BasicStroke;
import com.jrefinery.data.BasicTimeSeries;
import com.jrefinery.data.Month;
import com.jrefinery.data.*;
import com.jrefinery.data.XYDataset;
import com.jrefinery.data.TimeSeriesCollection;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.StandardXYItemRenderer;
import com.jrefinery.chart.XYItemRenderer;
import com.jrefinery.chart.Marker;
import com.jrefinery.chart.XYPlot;
import com.jrefinery.ui.RefineryUtilities;
import com.jrefinery.chart.NumberAxis;
import com.jrefinery.chart.tooltips.CustomXYToolTipGenerator;
import java.util.ArrayList;

public class TimeSeriesDemoa extends ApplicationFrame {
public CustomXYToolTipGenerator ttgatd = new CustomXYToolTipGenerator();
public ArrayList toolTipATD = new ArrayList();

public TimeSeriesDemoa(String title) {

super(title);

ttgatd.addToolTipSeries(toolTipATD);

String charttype2="ATDS";
StandardXYItemRenderer atdrenderer = new StandardXYItemRenderer();
atdrenderer.setPlotLines(false);
atdrenderer.setPlotShapes(true);
atdrenderer.setToolTipGenerator(ttgatd);
XYSeriesCollection atddataset = new XYSeriesCollection();
XYSeries atdseries = new XYSeries("ATDS",true);
atddataset = new XYSeriesCollection(atdseries);
JFreeChart atdchart;
atdchart = ChartFactory.createScatterPlot("ATDs", "Time (s)", "Metres",atddataset, true);
XYPlot atdplot = atdchart.getXYPlot();
atdplot.setRenderer(atdrenderer);
NumberAxis atdxaxis = (NumberAxis) atdplot.getDomainAxis();
atdxaxis.setAutoRange(true);
atdxaxis.setAutoRangeIncludesZero(false);
NumberAxis atdyaxis = (NumberAxis) atdplot.getRangeAxis(); //y axis
atdyaxis.setAutoRange(true);
atdyaxis.setAutoRangeIncludesZero(false);
// save as new graph

int i;
XYSeries dataSeries = new XYSeries("ID=1");

for (i=0;i<15;i++){
atdseries.add(100,i);
toolTipATD.add("ID="+i+" ,Time="+100);
}

ChartPanel chartPanel = new ChartPanel(atdchart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
this.setContentPane(chartPanel);

}

public static void main(String[] args) {

TimeSeriesDemoa demo = new TimeSeriesDemoa("Time Series Test");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}

Dave Gilbert

Re: Tooltips are out of order when x is duplicate

Post by Dave Gilbert » Wed Nov 27, 2002 1:24 pm

Hi Robert,

The problem is in the XYSeries class, which doesn't preserve the add order of duplicate items. But the CustomXYToolTipGenerator requires the order to be preserved, so it is a mismatch between these two classes. I've added it as BUG 644689 on SourceForge so I don't forget about it.

Regards,

DG

Locked