使用Android Plot根据时间点绘制CSV值

时间:2016-05-19 07:07:06

标签: android-studio time opencsv androidplot

enter image description here

该图像是csv文件的一部分的屏幕截图。 D列表示时间(从早上6点到下午6点,以几秒的间隔进行测量),而其他列是参数。如何使用AndroidPlot将这些参数与测量时间(例如以小时为单位,但允许放大)进行绘制?

以下是应该实施情节的活动的一部分,但不起作用:

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();
    }

0 个答案:

没有答案