无法从我的数据列表中绘制我的LineChart

时间:2018-01-10 11:07:06

标签: android firebase mpandroidchart

下面是显示我的LineChart的代码 从Firebase检索一组数据后,用于绘制折线图。不知怎的,我无法将我的数据集显示到x和y轴以及LineChart本身。请帮忙。我的x轴是“Date:mm / dd / yy”,而我的y轴是Float Data

private void displayGraph() {

        //Storage for (String) dates from Firebase: public ArrayList<String> x_axis = new ArrayList<>();
        //public ArrayList<String> y_axis = new ArrayList<>()
        ArrayList<String> xVals = new ArrayList<>();
        ArrayList<Entry> yVals = new ArrayList<>();
        int times = 0;

        //date as for X - axis
        for (String xaxis : x_axis) {
            xVals.add(xaxis);
        }

        //values from my y_axis ArrayList to Y - axis
        for (String item : y_axis) {
            yVals.add(new Entry(Float.valueOf(item), times));
            times++;
        }

        //for Y axis
        LineDataSet yValue = new LineDataSet(yVals, "Consumed");

        LineData xydata = new LineData(xVals, yValue);
        linechart.setData(xydata);
        linechart.getXAxis().setTextColor(Color.WHITE);
        linechart.invalidate();

    }

0 个答案:

没有答案