XYplot points not displaying at correct(expected) location

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
vscalfari
Posts: 6
Joined: Mon Apr 04, 2016 6:43 pm
antibot: No, of course not.

XYplot points not displaying at correct(expected) location

Post by vscalfari » Wed Jul 20, 2016 2:02 pm

The points on my XY plot seem to be offset, but I don't know why. See the picture below

(right click and select open in new tab) - couldn't figure out how to embed this..
Image

I have set the XY locations as follows for the WHITE points:
1 - -4.5, 4.5
2 - -0.5, 0.5
3 - -2.62, 2.62
4 - -1.31, 1.31
5 - -3.93, 3.93

Does anyone know why my points would be offset the way they are so they are not exactly on the intersections they should be on?

I customized my gridlines to try and match the other lines in my background plot image (if you see any white lines, that is actually in the background image).
When this program actually runs, I will hide the JFreechart gridlines and labels, so I don't need those to look pretty. I thought matching them to the background gridlines would make it easier to place the points in the correct locations.

My gridlines were customized using the following method:

Code: Select all

    public void customizeGridLines(XYPlot xy)
    {

        //get x and y axis, set them to invisible
        ValueAxis range = xy.getRangeAxis();
        ValueAxis domain = xy.getDomainAxis();
        NumberAxis numRange = (NumberAxis) range;
        NumberAxis numDomain = (NumberAxis) domain;
        //EDIT - COMMENT OUT LATER
        xy.setDomainGridlinePaint(Color.BLACK);
        xy.setRangeGridlinePaint(Color.BLACK);
        //EDIT - CHANGE TO FALSE LATER
        range.setVisible(true);
        domain.setVisible(true);
        xy.setDomainGridlinesVisible(true);
        xy.setRangeGridlinesVisible(true);
        
        //set range of entire plot
        range.setLowerBound(plotRange*-1.0);
        range.setUpperBound(plotRange);
        domain.setLowerBound(plotRange*-1.0);
        domain.setUpperBound(plotRange);
        
        double upperValue = range.getUpperBound(); 
        //set ticks
        //numRange.setTickUnit(new NumberTickUnit(1.31,NumberFormat.getIntegerInstance()));
        //numDomain.setTickUnit(new NumberTickUnit(1.31,NumberFormat.getIntegerInstance()));
        numRange.setRange(-6.0, 6.0);
        numRange.setTickUnit(new NumberTickUnit(1.31));
        numDomain.setRange(-6.0, 6.0);
        numDomain.setTickUnit(new NumberTickUnit(1.31));
    }
and my chart is made by calling this line:

Code: Select all

plot = ChartFactory.createScatterPlot(chartTitle, yString, xString, dataset, PlotOrientation.VERTICAL, true, true, true);
where dataset contains all of my points that I have created.

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

Re: XYplot points not displaying at correct(expected) locati

Post by paradoxoff » Wed Jul 20, 2016 2:17 pm

Since neither the shapes nor the colors nor the background in your XYPlot are the ones of a "default" XYPlot, I assume that you have changed those properties outside the code that you have posted. During the change, you probably have chosen Shapes that are not centered at 0,0 (e. g. an Ellipse2D.Double(0, 0, 12, 12) instead of the correct Ellipse2D.Double(-6, -6, 12, 12)).

vscalfari
Posts: 6
Joined: Mon Apr 04, 2016 6:43 pm
antibot: No, of course not.

Re: XYplot points not displaying at correct(expected) locati

Post by vscalfari » Wed Jul 20, 2016 2:25 pm

Thanks for your quick reply. Sorry for not including the point shape definition. The points are set to the shape below:

Code: Select all

    private double defaultSize = 15.0;
    private Shape defaultShape = new Ellipse2D.Double(0, 0, defaultSize, defaultSize);
So you are saying the Shape should be:

Code: Select all

    private double defaultSize = 15.0;
    private Shape defaultShape = new Ellipse2D.Double(-6.0, -6.0, defaultSize, defaultSize);
correct?

PS- I just edited my code to the shape above and it works perfectly now. Thank you so much!

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

Re: XYplot points not displaying at correct(expected) locati

Post by paradoxoff » Wed Jul 20, 2016 3:50 pm

Just to make this clear: you should use shapes that are centered at 0,0, e. g.

Code: Select all

double size = 15.0;//or whatever values is appropiate.
Shape s = new Ellipse2D.Double(-size/2.0, -size/2.0, size, size);

vscalfari
Posts: 6
Joined: Mon Apr 04, 2016 6:43 pm
antibot: No, of course not.

Re: XYplot points not displaying at correct(expected) locati

Post by vscalfari » Wed Jul 20, 2016 4:05 pm

Ohhh, ok I got it now. That did make it clearer, thanks.

I've edited my code.

Sorry, I got confused by the hardcoded numbers in your other post. I guess it looked ok because 6 was close enough to 15(my default size) divided by 2 to look ok, but it was not actually correct.

Locked