1

enter image description here

The image is a screenshot of a portion of a csv file. Column D indicates time (from 6 am to 6 pm, measurements taken at intervals of a few seconds) while the other columns are parameters. How can I plot these parameters against time of measurement (say in hours, but zooming in is permitted) using AndroidPlot?

Here is a portion of the activity that is supposed to implement the plot, but is not working:

CSVReader csvReader = new CSVReader(new FileReader(FileName));

        String[] nextLine;
        int rowNumber = 1;


        while ((nextLine = csvReader.readNext()) != null) {
            list1.add(nextLine[4]);  //Column E
            rowNumber++;
        }


        int i = 1;

        Float[] series1numbers = new Float[list1.size()];



        while (list1.get(i) != null) {
            series1numbers[i] = Float.parseFloat(list1.get(i));
            i++;
        }

        mySimpleXYPlot = (XYPlot) findViewById(R.id.SolarVoltage);


        // Turn the above arrays into XYSeries':
        XYSeries series1 = new SimpleXYSeries(
                Arrays.asList(series1numbers),
                SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
                        // SimpleXYSeries takes a List so turn our array into a List,                                           // Y_VALS_ONLY means use the element index as the x value
                "Column E");                             // Set the display title of the series

        // Create a formatter to use for drawing a series using LineAndPointRenderer:
        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0),                   // line color
                Color.rgb(0, 100, 0),                   // point color
                null,                                   // fill color (none)
                new PointLabelFormatter(Color.WHITE));                           // text color

        // add a new series' to the xyplot:
        mySimpleXYPlot.addSeries(series1, series1Format);

        // reduce the number of range labels
        mySimpleXYPlot.setTicksPerRangeLabel(3);


        Toast.makeText(MyActivity.this, "File Access Permitted", Toast.LENGTH_SHORT).show();

    }


    catch (Exception e) {
        Toast.makeText(getBaseContext(), "File Access Denied", Toast.LENGTH_SHORT).show();
        Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
AR06
  • 161
  • 1
  • 2
  • 16
  • The problem with your question is that I don't know what you are asking . you have a problem but you have multiple things going on in your code. When you say it does not work - how did it not work? So do this after you read into your list of strings print your list of strings and size and verify that is correct. After you convert to float print that array out and verify. if both of those are okay then the issue is most likely android plot. hard code an array of 10 values and see if that works. then try with real data but subsets to see if a specific value is wrong. – Scott Conway May 22 '16 at 21:57
  • Then try larger subsets because it could be that there is a limit on how many points can be plotted. – Scott Conway May 22 '16 at 22:01
  • @ScottConway I have managed to get the plot working for all values. However, I am not certain about how to plot time (column D) on X-axis since it needs to be in terms of hours. On clicking on the point of interest, how can it display the exact time? – AR06 May 23 '16 at 15:07

0 Answers0