[XYShapeRenderer/LookupPaintScale]Crosshair not locking data

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

[XYShapeRenderer/LookupPaintScale]Crosshair not locking data

Post by NaggingDaivy » Tue Feb 07, 2017 11:09 am

Hello again and sorry for multiple posts but I can't manage to solve the problems.

I am using an XYShapeRenderer with a LookUpPaintScale and I want to lock the crosshair on the data that I use.

Howerver, it doesn't work, however it works with XYShapeAndLineRenderer...

Here is my code :

Code: Select all

private void createPanel() throws FileNotFoundException, IOException {
 
        List<String> listX = new ArrayList<>();
        List<String> listY = new ArrayList<>();
        List<String> listZ = new ArrayList<>();
        String strFileName = "C:\\Users\\Daivy\\Documents\\NetBeansProjects\\TestFreeChart\\Test1.xyz";
 
        ReadXYZFile(strFileName, listX, listY, listZ);
 
        double[] arrayOfDoubleX = new double[listX.size()];
        double[] arrayOfDoubleY = new double[listY.size()];
        double[] arrayOfDoubleZ = new double[listZ.size()];
 
        for (int x = 0; x < arrayOfDoubleX.length; ++x) {
            arrayOfDoubleX[x] = Double.parseDouble(listX.get(x));
        }
 
        for (int y = 0; y < arrayOfDoubleY.length; ++y) {
            arrayOfDoubleY[y] = Double.parseDouble(listY.get(y));
        }
 
        for (int z = 0; z < arrayOfDoubleZ.length; ++z) {
            arrayOfDoubleZ[z] = Double.parseDouble(listZ.get(z));
        }
 
        double[][] arrayOfDouble = {arrayOfDoubleX, arrayOfDoubleY, arrayOfDoubleZ};
 
        //AXIS X
        NumberAxis localNumberAxisX = new NumberAxis("X");
        localNumberAxisX.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 
 
        //AXISY
        NumberAxis localNumberAxisY = new NumberAxis("Y");
        localNumberAxisY.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
 
        //DATASET, where values need to be added
        DefaultXYZDataset defaultXYZDataset = new DefaultXYZDataset();
        defaultXYZDataset.addSeries("Series 1", arrayOfDouble);
       
 
        //LOOKUP PAINTSCALE
        LookupPaintScale localLookupPaintScale = new LookupPaintScale(-4, 4, Color.blue);
       
        localLookupPaintScale.add(-4.0D, new Color(238, 152, 255));
        localLookupPaintScale.add(-3.0D, new Color(214, 152, 255));
        localLookupPaintScale.add(-0.1D, new Color(191, 152, 255));
        localLookupPaintScale.add(-2.0D, new Color(157, 159, 255));
        localLookupPaintScale.add(-1.0D, new Color(152, 185, 255));
        localLookupPaintScale.add(-0.5D, new Color(152, 245, 255));
        localLookupPaintScale.add(-0.1D, new Color(255, 255, 0));
        localLookupPaintScale.add(0.1D, new Color(255, 204, 0));
        localLookupPaintScale.add(1.0D, new Color(255, 153, 0));
        localLookupPaintScale.add(2.0D, new Color(255, 102, 0));
        localLookupPaintScale.add(3.0D, new Color(255, 51, 0));
        localLookupPaintScale.add(4.0D, new Color(255, 0, 0));
       // localLookupPaintScale.add(5.0D, new Color(255, 0, 0));
 
        //RENDERER TO PRINT CHART ON SCREEN
        XYShapeRenderer xyShapeRenderer = new XYShapeRenderer();
       
        xyShapeRenderer.setPaintScale(localLookupPaintScale);
       
        xyShapeRenderer.setSeriesShape(0, new Rectangle2D.Double(-1,-1,10,10));
       
 
 
        XYPlot xyPlot = new XYPlot(defaultXYZDataset, localNumberAxisX, localNumberAxisY, xyShapeRenderer);
       
        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setDomainCrosshairLockedOnData(true);
        xyPlot.setRangeCrosshairVisible(true);
        xyPlot.setRangeCrosshairLockedOnData(true);
        xyPlot.setDomainZeroBaselineVisible(true);
        xyPlot.setRangeZeroBaselineVisible(true);
       
 
        //
        JFreeChart jFreeChart = new JFreeChart("Test", xyPlot);
 
        //PAINT SCALE
        NumberAxis localNumberAxis = new NumberAxis("Error(mm)");
        localNumberAxis.setAxisLinePaint(Color.white);
        localNumberAxis.setTickMarkPaint(Color.white);
        localNumberAxis.setTickLabelFont(new Font("Dialog", 0, 7));
 
        PaintScaleLegend localPaintScaleLegend = new PaintScaleLegend(localLookupPaintScale, localNumberAxis);
        localPaintScaleLegend.setStripOutlineVisible(false);
 
        localPaintScaleLegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        localPaintScaleLegend.setAxisOffset(5.0D);
        localPaintScaleLegend.setMargin(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));//NO
        localPaintScaleLegend.setFrame(new BlockBorder(Color.red));
        localPaintScaleLegend.setPadding(new RectangleInsets(10.0D, 10.0D, 10.0D, 10.0D)); //NO
        localPaintScaleLegend.setStripWidth(10.0D); //NO
        localPaintScaleLegend.setPosition(RectangleEdge.LEFT);
     
 
        jFreeChart.addSubtitle(localPaintScaleLegend);
        ChartUtilities.applyCurrentTheme(jFreeChart);
 
       
   
        this.chartPanel = new ChartPanel(jFreeChart);
       
       
       this.chartPanel.setMouseWheelEnabled(true);
         
    }

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Tue Feb 07, 2017 1:29 pm

It's usually better if you post some code that is self-contained so others can compile and run it directly.

I don't know a reason why this wouldn't work with XYShapeRenderer. I modified XYShapeRendererDemo1.java to show crosshairs and they work for me. There is a bug that I was just looking at, but it only affects data points plotted against secondary axes so I don't think that is the issue for you. So, please try to post a small self contained demo and I'll take another look.
David Gilbert
JFreeChart Project Leader

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

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Tue Feb 07, 2017 3:37 pm

david.gilbert wrote:It's usually better if you post some code that is self-contained so others can compile and run it directly.

I don't know a reason why this wouldn't work with XYShapeRenderer. I modified XYShapeRendererDemo1.java to show crosshairs and they work for me. There is a bug that I was just looking at, but it only affects data points plotted against secondary axes so I don't think that is the issue for you. So, please try to post a small self contained demo and I'll take another look.
Hi David, here is my full code, you can copy paste and it should run directly ; I can't still find why crosshairs does not show :/

Code: Select all

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testfreechart;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.LookupPaintScale;
import org.jfree.chart.title.PaintScaleLegend;
import org.jfree.data.xy.DefaultXYZDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.renderer.xy.XYShapeRenderer;

/**
 *
 * @author Daivy
 */
public class TestXYZChart2 extends ApplicationFrame {
  
    public static void main(String[] paramArrayOfString) throws IOException {
        TestXYZChart2 testXYZChart = new TestXYZChart2("JFreeChart: TestXYZChart");
        testXYZChart.pack();
        RefineryUtilities.centerFrameOnScreen(testXYZChart);
        testXYZChart.setVisible(true);
    }
    
    private ChartPanel createPanel() {

 

        double[] arrayOfDoubleX = {0,1,2,3,4};
        double[] arrayOfDoubleY = {0,1,2,3,4};
        double[] arrayOfDoubleZ = {0,1,2,3,4};

 
        double[][] arrayOfDouble = {arrayOfDoubleX, arrayOfDoubleY, arrayOfDoubleZ};

        //AXIS X
        NumberAxis localNumberAxisX = new NumberAxis("X");
        localNumberAxisX.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

  
        //AXISY
        NumberAxis localNumberAxisY = new NumberAxis("Y");
        localNumberAxisY.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
       

        //DATASET, where values need to be added
        DefaultXYZDataset defaultXYZDataset = new DefaultXYZDataset();
        defaultXYZDataset.addSeries("Series 1", arrayOfDouble);
        

        //LOOKUP PAINTSCALE
        LookupPaintScale localLookupPaintScale = new LookupPaintScale(-4, 4, Color.blue);
        
        
        //Only for testing
        localLookupPaintScale.add(-4.0D, new Color(238, 152, 255));
        localLookupPaintScale.add(-3.0D, new Color(214, 152, 255));
        localLookupPaintScale.add(-0.1D, new Color(191, 152, 255));
        localLookupPaintScale.add(-2.0D, new Color(157, 159, 255));
        localLookupPaintScale.add(-1.0D, new Color(152, 185, 255));
        localLookupPaintScale.add(-0.5D, new Color(152, 245, 255));
        localLookupPaintScale.add(-0.1D, new Color(255, 255, 0));
        localLookupPaintScale.add(0.1D, new Color(255, 204, 0));
        localLookupPaintScale.add(1.0D, new Color(255, 153, 0));
        localLookupPaintScale.add(2.0D, new Color(255, 102, 0));
        localLookupPaintScale.add(3.0D, new Color(255, 51, 0));
        localLookupPaintScale.add(4.0D, new Color(255, 0, 0));
      

        //RENDERER TO PRINT CHART ON SCREEN
        XYShapeRenderer xyShapeRenderer = new XYShapeRenderer();
      
        //ADD PAINT SCALE TO RENDERER
        xyShapeRenderer.setPaintScale(localLookupPaintScale);
        
        xyShapeRenderer.setSeriesShape(0, new Rectangle2D.Double(-1,-1,10,10));
        
       //XYPLOT

        XYPlot xyPlot = new XYPlot(defaultXYZDataset, localNumberAxisX, localNumberAxisY, xyShapeRenderer);
        

        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setDomainCrosshairLockedOnData(true);
        xyPlot.setRangeCrosshairVisible(true);
        xyPlot.setRangeCrosshairLockedOnData(true);
        xyPlot.setDomainZeroBaselineVisible(true);
        xyPlot.setRangeZeroBaselineVisible(true);
        

        //
        JFreeChart jFreeChart = new JFreeChart("Test", xyPlot);

        //PAINT SCALE
        NumberAxis localNumberAxis = new NumberAxis("Error(mm)");
        localNumberAxis.setAxisLinePaint(Color.white);
        localNumberAxis.setTickMarkPaint(Color.white);
        localNumberAxis.setTickLabelFont(new Font("Dialog", 0, 7));

        PaintScaleLegend localPaintScaleLegend = new PaintScaleLegend(localLookupPaintScale, localNumberAxis);
        localPaintScaleLegend.setStripOutlineVisible(false);

        localPaintScaleLegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        localPaintScaleLegend.setAxisOffset(5.0D);
        localPaintScaleLegend.setMargin(new RectangleInsets(5.0D, 5.0D, 5.0D, 5.0D));//NO
        localPaintScaleLegend.setFrame(new BlockBorder(Color.red));
        localPaintScaleLegend.setPadding(new RectangleInsets(10.0D, 10.0D, 10.0D, 10.0D)); //NO
        localPaintScaleLegend.setStripWidth(10.0D); //NO
        localPaintScaleLegend.setPosition(RectangleEdge.LEFT);
        // Affiche la legende

        jFreeChart.addSubtitle(localPaintScaleLegend);
        ChartUtilities.applyCurrentTheme(jFreeChart);
        
        ChartPanel chartPanel = new ChartPanel(jFreeChart);
        
      
        chartPanel.setMouseWheelEnabled(true);
        
        return chartPanel;
     
    }
    
    public TestXYZChart2(String title) throws IOException {
        super(title);
        
        JPanel localJPanel = createPanel();
        localJPanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(localJPanel);

    }
}

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Tue Feb 07, 2017 6:01 pm

When I run the code, the crosshairs are shown after you click on the chart with the mouse.
David Gilbert
JFreeChart Project Leader

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

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Wed Feb 08, 2017 3:03 pm

david.gilbert wrote:When I run the code, the crosshairs are shown after you click on the chart with the mouse.
What ? That is not the case when I run it... I dont understand...

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by John Matthews » Wed Feb 08, 2017 6:56 pm

I see the crosshairs immediately, but they are easier to see if I zoom out both axes using either the mouse wheel or the context menu:

Image

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Thu Feb 09, 2017 10:35 am

John Matthews wrote:I see the crosshairs immediately, but they are easier to see if I zoom out both axes using either the mouse wheel or the context menu:

Image
Yes, but when I click on a dot, the axes are not crossing. That is my problem : I want the axes to cross when clicking on a dot, like in ScatterPlotDemo2.

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by paradoxoff » Thu Feb 09, 2017 11:21 am

So the "visibility" of the "axes" was never the problem, but only the fact that they do not "cross"?
Your error description doesn't make much sense to me. Let me rephrase it:
The trace lines for the crosshair do not cross in the center of the symbol.
if that description is true, then you should use a series shapes that is centered at the origin (such as a Rectangle2D.Double(-5, -5, 10, 10)) and not a Rectangle2D.Double(-1, -1, 10, 10), because that will be be shifted towards the lower right corner.

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Thu Feb 09, 2017 11:34 am

paradoxoff wrote:So the "visibility" of the "axes" was never the problem, but only the fact that they do not "cross"?
Your error description doesn't make much sense to me. Let me rephrase it:
The trace lines for the crosshair do not cross in the center of the symbol.
if that description is true, then you should use a series shapes that is centered at the origin (such as a Rectangle2D.Double(-5, -5, 10, 10)) and not a Rectangle2D.Double(-1, -1, 10, 10), because that will be be shifted towards the lower right corner.
No, actually, what I meant was to do the same thing as in ScatterPlotDemo2 : when clicking on a dot(http://imgur.com/a/y7FZ1) , a blue crosshair appear. I want also to know the coordonnate of the dot that the user clicked. So for me, that was pretty clear when I said "Locking crosshair on data". Sorry if I was wrong.

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by paradoxoff » Thu Feb 09, 2017 12:54 pm

I copy-pasted the code and ran it. Results are the same as for NaggingDaivy: trace lines do not appear with an XYShapeRenderer, but with an XYLineAndShapeRenderer. I have no idea why this is happening.

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Thu Feb 09, 2017 1:05 pm

paradoxoff wrote:I copy-pasted the code and ran it. Results are the same as for NaggingDaivy: trace lines do not appear with an XYShapeRenderer, but with an XYLineAndShapeRenderer. I have no idea why this is happening.
It is also working with XYDotRenderer, but I can't use it because I need a LookUpPaintScale. :/
Edit : With XYBlockRenderer, it does not work either.

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Fri Feb 10, 2017 4:53 pm

There is a bug fix in the XYShapeRenderer class made after the 1.0.19 release:

https://sourceforge.net/p/jfreechart/code/3312/

Note that the source code is maintained at GitHub now, not in the the SVN repo at SourceForge.
David Gilbert
JFreeChart Project Leader

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

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Tue Feb 14, 2017 9:14 am

david.gilbert wrote:There is a bug fix in the XYShapeRenderer class made after the 1.0.19 release:

https://sourceforge.net/p/jfreechart/code/3312/

Note that the source code is maintained at GitHub now, not in the the SVN repo at SourceForge.
Ok, so I have to download on Github then building the sources ? Why are you not including these fixes with the jar on the download page of your website?

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

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by david.gilbert » Tue Feb 14, 2017 10:28 am

The next release will include the fixes. There hasn't been a release for a long time since there is some effort involved and I've had other priorities...but I'm working on a release at the moment. In the meantime, yes downloading the sources and building the jar yourself is the only way to get that fix.
David Gilbert
JFreeChart Project Leader

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

NaggingDaivy
Posts: 21
Joined: Mon Jan 09, 2017 2:04 pm
antibot: No, of course not.

Re: [XYShapeRenderer/LookupPaintScale]Crosshair not locking

Post by NaggingDaivy » Tue Feb 14, 2017 10:58 am

david.gilbert wrote:The next release will include the fixes. There hasn't been a release for a long time since there is some effort involved and I've had other priorities...but I'm working on a release at the moment. In the meantime, yes downloading the sources and building the jar yourself is the only way to get that fix.
Thank you David !

Locked