LarissaHortencio10 / charts4j

Automatically exported from code.google.com/p/charts4j
Other
0 stars 0 forks source link

XYLine with only one point is always at x = 0 #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If I create a xyline with only one point, the x value is not taken into 
account. 
ex :
XYLine plot = Plots.newXYLine(new Data(50.0d), new Data(75.0d), Color.RED, 
"Bla"); 
the point will be at position (0,75) !

Thanks in advance for any help

Original issue reported on code.google.com by pierregi...@gmail.com on 9 Jan 2014 at 9:50

GoogleCodeExporter commented 8 years ago
I vaguely remember this problem (I think it is a bug in the underlying google 
charts api). As a workaround, please try a scatter plot, or a regular line 
chart.

Original comment by Julien.C...@gmail.com on 9 Jan 2014 at 4:43

GoogleCodeExporter commented 8 years ago
Thanks Julien for your answer.

My case is more complex : I have n plots and some may have only one points 
depending on user's config.

Following please find the simplest similair code.

Is it possible to replace (and how) the XYLine plot2 by a scatter plot or a 
regular line in this XYLineChart ?

Thanks in advance

Pierre

        ArrayList<XYLine> plots = new ArrayList<XYLine>();
        ArrayList<Double> listeAbs = new ArrayList<Double>();
        ArrayList<Double> listeScore = new ArrayList<Double>();
        listeAbs.add(50.0d);
        listeScore.add(75.0d);
        listeAbs.add(60.0d);
        listeScore.add(25.0d);

 // first graph       
        XYLine plot = Plots.newXYLine(Data.newData(listeAbs), Data.newData(listeScore), Color.RED, "Graph 2 points ok");

        plot.addShapeMarkers(Shape.DIAMOND,  Color.RED, 12);
        plot.addShapeMarkers(Shape.DIAMOND, Color.WHITE, 8);
        plot.setLineStyle(LineStyle.newLineStyle(3, 1, 0));

        plots.add(plot);

// 2nd graph with 1 point 
        ArrayList<Double> listeAbs2 = new ArrayList<Double>();
        ArrayList<Double> listeScore2 = new ArrayList<Double>();
        listeAbs2.add(60.0d);
        listeScore2.add(75.0d);

        XYLine plot2 = Plots.newXYLine(Data.newData(listeAbs2), Data.newData(listeScore2), Color.BLACK, "Faulty Graph with 1 point");

        plot2.addShapeMarkers(Shape.DIAMOND,  Color.BLACK, 12);
        plot2.addShapeMarkers(Shape.DIAMOND, Color.WHITE, 8);
        plot2.setLineStyle(LineStyle.newLineStyle(3, 1, 0));

        plots.add(plot2);

        XYLineChart chart = GCharts.newXYLineChart(plots);

Original comment by pierregi...@gmail.com on 10 Jan 2014 at 9:32

GoogleCodeExporter commented 8 years ago
Dont bother answer me, I find an easy workaround

1)Testing if only one point
2) if true, add a dummy point very close to the real one.
....
listeAbs2.add(60.0d);
listeScore2.add(75.0d);
if (listeAbs2.size() == 1)
{
  listeAbs2.add(60.0d);
  listeScore2.add(75.01d);
}

Original comment by pierregi...@gmail.com on 11 Jan 2014 at 3:30

GoogleCodeExporter commented 8 years ago
OK I am glad that worked for you.

Original comment by Julien.C...@gmail.com on 11 Jan 2014 at 11:02