2

I am using https://github.com/jjoe64/GraphView for a real-time android graph application. I am using 4.1.0 library version. I am using graph view to display a parameter (battery voltage) and change the color of line graph based on a certain value. For example, if I have < 12.0 Volts I want to change the line color to RED, and if its <12.5 Volts I want it to be yellow, etc, etc.
The trouble I have is the color of the entire lineGraph changes to the most recent value. I want the line to consist the appropriate color based on the Voltage.I do not wish to use PointGraph, I have been finding a lot of answers around that but that's beyond the scope of my application. I am using the following code:

   LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[]{}); 
            Paint paint = new Paint();
            double graph2LastXValue = 5d;

// real time logic which gets voltageAtLocation

            graph2LastXValue += 1d;

            if (voltageAtLocation > 12.50) {
                paint.setColor(Color.GREEN);

            } else if (voltageAtLocation > 12.00) {
                paint.setColor(Color.YELLOW);
            }
            else {
                paint.setColor(Color.RED);
            }
            series.appendData(new DataPoint(graph2LastXValue, voltageAtLocation), true, 100);
            series.setCustomPaint(paint);
DKV
  • 1,767
  • 3
  • 28
  • 49
Rav Brar
  • 21
  • 2

0 Answers0