I want to make multiple lines in real time using MPAndroidChart .
There is no need to schedule real-time using only one data. (following code)
private void addEntry(int count) { LineData data = mChart.getData(); if (data != null) { LineDataSet set = data.getDataSetByIndex(0); if (set == null) { set = createSet(); data.addDataSet(set); } data.addXValue(""); data.addEntry(new Entry(getPressure(), set.getEntryCount()), 0); data.setDrawValues(false); data.setHighlightEnabled(false);
And it is not a problem to make a few lines using the following code.
private void setData(int count, float range) { ArrayList<String> xValues = new ArrayList<String>(); for (int i = 0 ; i < count ; i++) { xValues.add((1 + i) + ""); } ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); for (int k = 0 ; k < 3 ; k++) { ArrayList<Entry> yValues = new ArrayList<Entry>(); for (int i = 0 ; i < count ; i++) { if (k == 0) { yValues.add(new Entry(getSetPressure(), i)); } else if (k == 1) { yValues.add(new Entry(getCurrentPressure(), i)); } else { yValues.add(new Entry(getSuctionPressure(), i)); } } String s; String c; if (k == 0) { s = "Set Pressure"; c = "#ed1f24"; } else if (k == 1) { s = "Current Pressure"; c = "#004bf6"; } else { s = "Suction Pressure"; c = "#ffba00"; } LineDataSet set = new LineDataSet(yValues, s); set.setAxisDependency(YAxis.AxisDependency.LEFT); set.setDrawCubic(false); set.setDrawCircles(false); set.setCircleColor(Color.parseColor(c)); set.setCircleSize(8f); set.setCircleColorHole(Color.BLACK); set.setDrawCircleHole(false); set.setLineWidth(3f); set.setColor(Color.parseColor(c)); set.setDrawHorizontalHighlightIndicator(false); set.setDrawVerticalHighlightIndicator(false); dataSets.add(set); } LineData data = new LineData(xValues, dataSets); data.setDrawValues(false); data.setHighlightEnabled(false); mChart.setData(data); }
However, I do not know how to make several lines in a line graph in real time.
How to make multiple lines in real time?
source share