Search code examples
androidandroid-graphview

Android GraphView multiple series show/hide particular linegraph on touch


I am using GraphView for Android with multiple series to show 2 graphs. Is it even a possibility to show/hide one of the graphs on touch, because I couldn't find any documentation on the website?

Here is the source code:

graph = (GraphView) findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<>(new DataPoint[] {
    new DataPoint(0, 1),
    new DataPoint(1, 5),
    new DataPoint(2, 3),
    new DataPoint(3, 2),
    new DataPoint(4, 6)
});
graph.addSeries(series);

LineGraphSeries<DataPoint> series2 = new LineGraphSeries<>(new DataPoint[] {
    new DataPoint(0, 3),
    new DataPoint(1, 3),
    new DataPoint(2, 6),
    new DataPoint(3, 2),
    new DataPoint(4, 5)
});
graph.addSeries(series2);

Solution

  • Figured out the way, if anyone stumbled upon this problem. Created custom toggle/button that uses: graph.removeSeries()/graph.addSeries() and that should do the trick