Crosshair not locking on data of XYShapeRenderer

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Worblehat
Posts: 7
Joined: Tue Jun 30, 2015 1:01 pm
antibot: No, of course not.

Crosshair not locking on data of XYShapeRenderer

Post by Worblehat » Tue Jul 28, 2015 1:32 pm

Hi,

I have a XYPlot with visible crosshair and configured it to be "lockedOnData". Using a XYShapeAndLineRenderer this works fine, but with a XYShapeRenderer instead, the crosshair is not displayed. Looks like it is not able to lock on the data points of the XYShapeRenderer.

Any idea why?

Here I got a minimal working example that demonstrates it:

Code: Select all

public class Demo extends JFrame {

    public static void main(String[] args) {
        Demo demo = new Demo("Demo", "Demo-Chart");
        demo.pack();
        demo.setVisible(true);
    }

    public Demo(String applicationTitle, String chartTitle) {
        super(applicationTitle);

        XYPlot plot = new XYPlot();
        plot.setDomainAxis(new NumberAxis());
        plot.setRangeAxis(new NumberAxis());
        plot.setDomainCrosshairLockedOnData(true);
        plot.setRangeCrosshairLockedOnData(true);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        JFreeChart chart = new JFreeChart(chartTitle, plot);

        XYShapeRenderer renderer = new XYShapeRenderer();
        // With the following renderer, the crosshair works as expected:
        //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

        DefaultXYDataset dataset = new DefaultXYDataset();
        dataset.addSeries(0, createData());
        plot.setRenderer(0,renderer);
        plot.setDataset(0, dataset);

        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
        setContentPane(chartPanel);
    }

    private double[][] createData() {
        double[][] data = new double[2][5];
        data[0][0] = 1;
        data[0][1] = 2;
        data[0][2] = 3;
        data[0][3] = 4;
        data[0][4] = 5;
        data[1][0] = 4;
        data[1][1] = 7;
        data[1][2] = 2;
        data[1][3] = 6;
        data[1][4] = 4;
        return data;
    }
}

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Crosshair not locking on data of XYShapeRenderer

Post by paradoxoff » Tue Jul 28, 2015 4:36 pm

The last few lines in XYLineAndShapeRenderer contain these statements:

Code: Select all

int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,rangeAxisIndex, transX1, transY1, orientation);
These are missing from the code of XYShapeRenderer.
Try to add those lines, recompile the package, and let us know whether it worked.

Worblehat
Posts: 7
Joined: Tue Jun 30, 2015 1:01 pm
antibot: No, of course not.

Re: Crosshair not locking on data of XYShapeRenderer

Post by Worblehat » Fri Jul 31, 2015 11:33 am

Hi paradoxoff,

your suggested changes fixed the problem for me.

How do we get this patch into JFreeChart?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Crosshair not locking on data of XYShapeRenderer

Post by david.gilbert » Wed Sep 09, 2015 6:38 am

I'll add this tonight. Please remind me if I don't. :-)
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Crosshair not locking on data of XYShapeRenderer

Post by david.gilbert » Wed Sep 09, 2015 6:28 pm

David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Worblehat
Posts: 7
Joined: Tue Jun 30, 2015 1:01 pm
antibot: No, of course not.

Re: Crosshair not locking on data of XYShapeRenderer

Post by Worblehat » Tue Sep 15, 2015 3:36 pm

Thank you!

Locked