首页 > 解决方案 > 如何制作实时滴答线图(MpandroidChart)?

问题描述

我从一个字符串创建了一个数组列表,如下所示:

String strp = pprices.getText().toString().trim();
            String[] wordsp=strp.split("\\s+");
            int get_current_price = i_current_index;
            int next_60_seconds = i_current_index + 60;
            int s_launch = StringUtils.ordinalIndexOf(strp, " ", get_current_price);
            String split1 = strp.substring(0, s_launch);
            String split2 = strp.substring(s_launch);
            int s_required_60 = StringUtils.ordinalIndexOf(split2, " ", next_60_seconds);
            String split3 = strp.substring(0, s_required_60);
            String split4 = strp.substring(s_required_60);

List<Double> numberListp2 = new ArrayList<Double>();
            for (String numberTextp2 : split2.trim().split("\\s+"))
                numberListp2.add(Double.valueOf(numberTextp2));
            // To array
            int i2;
            String[] numberTextsp2 = split2.trim().split("\\s+");
            double[] numberArrayp2 = new double[numberTextsp2.length];
            for (i2 = 0; i2 < numberTextsp2.length; i2++) {
                numberArrayp2[i2] = Double.parseDouble(numberTextsp2[i2]);
            }
            //1. Set the x-axis and y-axis points
            List<Entry> entries2 = new ArrayList<>();
            for (i2 = 0; i2 < numberTextsp2.length; i2++) {
                entries2.add(new Entry(i2, (float) numberArrayp2[i2]));
                entry_count = i2;
            }

所以我正在使用这条线绘制:

entries2.add(new Entry(i2, (float) numberArrayp2[i2]));

XY坐标在哪里i2_(float) numberArrayp2[i2]

然后我有:

ArrayList<ILineDataSet> dataSets= new ArrayList<ILineDataSet>();
        LineDataSet dataSet2 = new LineDataSet(entries2, "Entry2");
        dataSets.add(dataSet2);
        LineData linedata = new LineData(dataSets);
        mChart.setData(linedata);

        mChart.invalidate(); // refresh

        data.notifyDataChanged();

此代码有效,并且折线图绘制得很好。

现在直接解决我的问题:

我不想一次绘制所有点,而是让它实时滴答作响,在点之间以 1000 毫秒的间隔一个接一个地绘制。

我怎样才能做到这一点?

标签: javaandroid-studiompandroidchartlinechart

解决方案


推荐阅读