#422 Crosshairs working wrong with multiple axis

1.0.x
closed-fixed
General (896)
5
2007-02-06
2004-12-16
Boente
No

If the chart has multiple axes, crosshairs are
displayed at the wrong position and sometimes
datapoints cannot be selected.

Use the following test-app (derived from CrosshairDemo2):

package test;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
import org.jfree.data.time.Minute;
import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
* An example of....
*/
public class TwoAxisCrosshairTest extends
ApplicationFrame {

private static final int SERIES_COUNT = 2;

private TimeSeriesCollection[] datasets;

private TimeSeries[] series;

private ChartPanel chartPanel;

/**
* A demonstration application showing how to...
*
* @param title the frame title.
*/
public TwoAxisCrosshairTest(String title) {

super(title);

this.datasets = new
TimeSeriesCollection[SERIES_COUNT];
this.series = new TimeSeries[SERIES_COUNT];

JPanel content = new JPanel(new BorderLayout());

JFreeChart chart = createChart();
this.chartPanel = new ChartPanel(chart);
this.chartPanel.setPreferredSize(new
java.awt.Dimension(600, 270));
content.add(this.chartPanel);

setContentPane(content);

}

/**
* Creates the demo chart.
*
* @return The chart.
*/
private JFreeChart createChart() {

JFreeChart chart =
ChartFactory.createTimeSeriesChart(
"Crosshair Demo 2",
"Time of Day",
"Value",
null,
true,
true,
false
);

XYDataset[] datasets = new XYDataset[SERIES_COUNT];
for (int i = 0; i < SERIES_COUNT; i++) {
datasets[i] = createDataset(i, "Series " +
i, 100.0 - i * 10.0, new Minute(), 10);
if (i == 0) {
chart.getXYPlot().setDataset(datasets[i]);

chart.getXYPlot().getRangeAxis(0).setLowerBound(0.0d);
}
else {
XYPlot plot = chart.getXYPlot();
plot.setDataset(i, datasets[i]);
plot.setRangeAxis(i, new
NumberAxis("Axis " + (i + 1)));
plot.mapDatasetToRangeAxis(i, i);
plot.setRenderer(i, new
DefaultXYItemRenderer());
}
}
XYPlot plot = chart.getXYPlot();

plot.setDomainCrosshairVisible(true);
plot.setDomainCrosshairLockedOnData(true);
plot.setRangeCrosshairVisible(true);
plot.setRangeCrosshairLockedOnData(true);

return chart;
}

/**
* Creates a sample dataset.
*
* @param index the dataset index.
* @param name the dataset name.
* @param base the starting value.
* @param start the starting period.
* @param count the number of values to generate.
*
* @return The dataset.
*/
private XYDataset createDataset(int index, String name,
double base,
RegularTimePeriod start, int count) {

this.series[index] = new TimeSeries(name,
start.getClass());
RegularTimePeriod period = start;
double value = base;
for (int i = 0; i < count; i++) {
this.series[index].add(period, value);
period = period.next();
value = value * (1 + (Math.random() -
0.495) / 10.0);
}

this.datasets[index] = new TimeSeriesCollection();
this.datasets[index].addSeries(this.series[index]);

return this.datasets[index];

}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {

TwoAxisCrosshairTest demo = new
TwoAxisCrosshairTest("Crosshair Demo 2");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}

Discussion

  • Nobody/Anonymous

    Logged In: NO

    to add to my latest comment. I now see that for some reason
    the crosshair are painted when showing up a chart panel
    initially even when no series are inside. For simple plots
    the line seem to coincide with the axis which is ok but for
    combined plot the y axis line of the crosshair is drawn
    right in the middle of the chart. I might investigate why
    it's doing this or go back to 1.0.0 with the patch.

     
  • Nobody/Anonymous

    Logged In: NO

    Not sure if this should be added here but the problem is now
    present again in 1.0.1-1.0.2 but not 1.0.0 because of the
    following

    version 1.0+ draws like this

    if (isRangeCrosshairVisible()
    &&
    getRangeAxis().getRange().contains(getRangeCrosshairValue())) {

    it uses getRangeAxis() which always return the axis 0 so
    therefore this will not work in multiple axis situation.
    Not sure what a permanent fix would be but we can go back to
    getCrosshairRangeAxis() instead.

     
  • Nobody/Anonymous

    Logged In: NO

    Sorry for my last comment look at the code that had the
    patch, so nothing changed it still doesn't work but works
    fine with the patch. I think it's about time that this
    patch be integrated in the main code tree.

     
  • Boente

    Boente - 2006-10-11
    • assigned_to: nobody --> mungady
     
  • Boente

    Boente - 2006-10-11

    Logged In: YES
    user_id=1098749

    Up to 1.0.2 it does not work in the unpatched freechart
    (patch ed version not tested). David can you please check if
    the pathch works and commit it to 1.0.3?
    Thanx!

     
  • David Gilbert

    David Gilbert - 2007-02-06
    • milestone: --> 1.0.x
    • status: open --> closed-fixed
     
  • David Gilbert

    David Gilbert - 2007-02-06

    Logged In: YES
    user_id=112975
    Originator: NO

    Thanks for the report and sorry for not dealing with this one sooner. I've committed a patch to CVS for inclusion in the upcoming 1.0.4 release. Closing as fixed.

    Regards,

    Dave Gilbert
    JFreeChart Project Leader

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks