jjoe64 / GraphView

Android Graph Library for creating zoomable and scrollable line and bar graphs.
https://github.com/jjoe64/GraphView/wiki
Other
2.76k stars 811 forks source link

Line graph not plotting negative lines #475

Open raicalvin opened 7 years ago

raicalvin commented 7 years ago

I'm having some trouble plotting a series of points that go back and forth about the y-axis. The GraphView does not connect the points with a line if the subsequent point is to the left of the preceding point.

For an example, if I try plotting the following points, the GraphView will not draw a line connecting points 2 & 3 and points 4 &5: Point 1: 0.0, 0.0 Point 2: 0.5, 1.0 Point 3: -0.25, 1.0 Point 4: 0.75, 3.0 Point 5: -0.5, 4.0

Here is an output of the points above. I want the GraphView to connect all the points:

negative lines

LineGraphSeries<DataPoint> series; GraphView graph = (GraphView) findViewById(R.id.modeShape); graph.removeAllSeries(); // clears the graph if there is a series is present series = new LineGraphSeries<>(new DataPoint[] { new DataPoint(0.0,0.0), new DataPoint(0.5,1.0), new DataPoint(-0.25,2.0), new DataPoint(0.75,3.0), new DataPoint(-0.5,4.0) }); graph.addSeries(series); graph.getViewport().setMinX(-1.0); graph.getViewport().setMaxX(1.0); graph.getViewport().setMinY(0.0); graph.getViewport().setMaxY(4.0);

Jetz72 commented 7 years ago

I believe GraphView currently expects points in the series to have increasing X values, so a line zig-zagging vertically like that isn't supported. Maybe you could swap your axes and travel along the X axis instead?

raicalvin commented 7 years ago

@Jetz72 - Thanks for getting back to me! I did find a 'quick fix' using a scatter plot instead of a line plot, but I'll definitely try to switch the axes to make it work. Thanks again! I appreciate it.