Java Code Examples for com.github.mikephil.charting.data.LineData#notifyDataChanged()
The following examples show how to use
com.github.mikephil.charting.data.LineData#notifyDataChanged() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneDayChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 动态增加一个点数据 * @param timeDatamodel * @param length */ public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); lineChart.setVisibleXRange(maxCount, maxCount); barChart.setVisibleXRange(maxCount, maxCount); //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() . lineChart.moveViewToX(index); barChart.moveViewToX(index); }
Example 2
Source File: FiveDayChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 动态增加一个点数据 * @param timeDatamodel * @param length */ public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); d1.addEntry(new Entry( index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); d2.addEntry(new Entry( index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry( index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); lineChart.setVisibleXRange(maxCount, maxCount); barChart.setVisibleXRange(maxCount, maxCount); //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() . lineChart.moveViewToX(index); barChart.moveViewToX(index); }
Example 3
Source File: DynamicalAddingActivity.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private void removeLastEntry() { LineData data = chart.getData(); if (data != null) { ILineDataSet set = data.getDataSetByIndex(0); if (set != null) { Entry e = set.getEntryForXValue(set.getEntryCount() - 1, Float.NaN); data.removeEntry(e, 0); // or remove by index // mData.removeEntryByXValue(xIndex, dataSetIndex); data.notifyDataChanged(); chart.notifyDataSetChanged(); chart.invalidate(); } } }
Example 4
Source File: PeerSheet.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private void update(@NonNull Peer peer) { LineData data = chart.getLineData(); if (data != null) { int pos = data.getEntryCount() + 1; data.addEntry(new Entry(pos, peer.downloadSpeed), Utils.CHART_DOWNLOAD_SET); data.addEntry(new Entry(pos, peer.uploadSpeed), Utils.CHART_UPLOAD_SET); data.notifyDataChanged(); chart.notifyDataSetChanged(); chart.setVisibleXRangeMaximum(60); chart.moveViewToX(data.getEntryCount()); } seeder.setHtml(R.string.seeder, String.valueOf(peer.seeder)); peerChoking.setHtml(R.string.peerChoking, String.valueOf(peer.peerChoking)); amChoking.setHtml(R.string.amChoking, String.valueOf(peer.amChoking)); downloadSpeed.setText(CommonUtils.speedFormatter(peer.downloadSpeed, false)); uploadSpeed.setText(CommonUtils.speedFormatter(peer.uploadSpeed, false)); bitfield.update(peer.bitfield, numPieces); int knownPieces = BitfieldVisualizer.knownPieces(peer.bitfield, numPieces); health.setHtml(R.string.health, ((float) knownPieces / (float) numPieces) * 100f, knownPieces, numPieces); PeerIdParser.Parsed parsed = peer.peerId(); if (parsed == null) peerId.setHtml(R.string.peerId, getString(R.string.unknown).toLowerCase()); else peerId.setHtml(R.string.peerId, parsed.toString()); }
Example 5
Source File: ServerSheet.java From Aria2App with GNU General Public License v3.0 | 5 votes |
private void update(@NonNull Server server) { downloadSpeed.setText(CommonUtils.speedFormatter(server.downloadSpeed, false)); LineData data = chart.getLineData(); if (data != null) { int pos = data.getEntryCount() + 1; data.addEntry(new Entry(pos, server.downloadSpeed), Utils.CHART_DOWNLOAD_SET); data.notifyDataChanged(); chart.notifyDataSetChanged(); chart.setVisibleXRangeMaximum(60); chart.moveViewToX(data.getEntryCount()); } currentUri.setHtml(R.string.currentUri, server.currentUri); uri.setHtml(R.string.uri, server.uri); }
Example 6
Source File: OneDayChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 动态更新最后一点数据 * @param timeDatamodel * @param length */ public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); Entry e = d1.getEntryForIndex(index); d1.removeEntry(e); d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); Entry e2 = d2.getEntryForIndex(index); d2.removeEntry(e2); d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); barDataSet.removeEntry(index); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); lineChart.moveViewToX(index); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); barChart.moveViewToX(index); }
Example 7
Source File: FiveDayChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 动态更新最后一点数据 * @param timeDatamodel * @param length */ public void dynamicsUpdateOne(TimeDataModel timeDatamodel, int length) { int index = length - 1; LineData lineData = lineChart.getData(); ILineDataSet d1 = lineData.getDataSetByIndex(0); Entry e = d1.getEntryForIndex(index); d1.removeEntry(e); d1.addEntry(new Entry( index, (float) timeDatamodel.getNowPrice())); ILineDataSet d2 = lineData.getDataSetByIndex(1); Entry e2 = d2.getEntryForIndex(index); d2.removeEntry(e2); d2.addEntry(new Entry( index, (float) timeDatamodel.getAveragePrice())); BarData barData = barChart.getData(); IBarDataSet barDataSet = barData.getDataSetByIndex(0); barDataSet.removeEntry(index); float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f; barDataSet.addEntry(new BarEntry( index, timeDatamodel.getVolume(),color)); lineData.notifyDataChanged(); lineChart.notifyDataSetChanged(); lineChart.moveViewToX(index); barData.notifyDataChanged(); barChart.notifyDataSetChanged(); barChart.moveViewToX(index); }
Example 8
Source File: DynamicalAddingActivity.java From StockChart-MPAndroidChart with MIT License | 5 votes |
private void addDataSet() { LineData data = chart.getData(); if (data == null) { chart.setData(new LineData()); } else { int count = (data.getDataSetCount() + 1); int amount = data.getDataSetByIndex(0).getEntryCount(); ArrayList<Entry> values = new ArrayList<>(); for (int i = 0; i < amount; i++) { values.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count)); } LineDataSet set = new LineDataSet(values, "DataSet " + count); set.setLineWidth(2.5f); set.setCircleRadius(4.5f); int color = colors[count % colors.length]; set.setColor(color); set.setCircleColor(color); set.setHighLightColor(color); set.setValueTextSize(10f); set.setValueTextColor(color); data.addDataSet(set); data.notifyDataChanged(); chart.notifyDataSetChanged(); chart.invalidate(); } }
Example 9
Source File: RealtimeLineChartActivity.java From StockChart-MPAndroidChart with MIT License | 5 votes |
private void addEntry() { LineData data = chart.getData(); if (data != null) { ILineDataSet set = data.getDataSetByIndex(0); // set.addEntry(...); // can be called as well if (set == null) { set = createSet(); data.addDataSet(set); } data.addEntry(new Entry(set.getEntryCount(), (float) (Math.random() * 40) + 30f), 0); data.notifyDataChanged(); // let the chart know it's data has changed chart.notifyDataSetChanged(); // limit the number of visible entries chart.setVisibleXRangeMaximum(120); // chart.setVisibleYRange(30, AxisDependency.LEFT); // move to the latest entry chart.moveViewToX(data.getEntryCount()); // this automatically refreshes the chart (calls invalidate()) // chart.moveViewTo(data.getXValCount()-7, 55f, // AxisDependency.LEFT); } }
Example 10
Source File: TickChart.java From android-kline with Apache License 2.0 | 5 votes |
public void refreshData(float price) { if (price <= 0 || price == mLastPrice) { return; } mLastPrice = price; LineData data = mChart.getData(); if (data != null) { ILineDataSet setSell = data.getDataSetByIndex(DATA_SET_PRICE); if (setSell == null) { setSell = createSet(TYPE_FULL); data.addDataSet(setSell); } data.removeEntry(setSell.getEntryCount(), DATA_SET_PRICE); Entry entry = new Entry(setSell.getEntryCount(), price); data.addEntry(entry, DATA_SET_PRICE); ILineDataSet paddingSet = data.getDataSetByIndex(DATA_SET_PADDING); if (paddingSet == null) { paddingSet = createSet(TYPE_DASHED); data.addDataSet(paddingSet); } int count = paddingSet.getEntryCount(); paddingSet.clear(); for (int i = 0; i < count; i++) { paddingSet.addEntry(new Entry(setSell.getEntryCount() + i, price)); } Highlight chartHighlighter = new Highlight(setSell.getEntryCount() + paddingSet.getEntryCount(), price, DATA_SET_PADDING); mChart.highlightValue(chartHighlighter); data.notifyDataChanged(); mChart.notifyDataSetChanged(); mChart.invalidate(); } }
Example 11
Source File: DownloadCardsAdapter.java From Aria2App with GNU General Public License v3.0 | 4 votes |
public void update(@NonNull DownloadWithUpdate download) { DownloadWithUpdate.SmallUpdate last = download.update(); if (last.status == Download.Status.ACTIVE) { detailsChart.setVisibility(View.VISIBLE); LineData data = detailsChart.getData(); if (data == null) { Utils.setupChart(detailsChart, true); data = detailsChart.getData(); } if (data != null) { int pos = data.getEntryCount() / 2 + 1; data.addEntry(new Entry(pos, last.downloadSpeed), Utils.CHART_DOWNLOAD_SET); data.addEntry(new Entry(pos, last.uploadSpeed), Utils.CHART_UPLOAD_SET); data.notifyDataChanged(); detailsChart.notifyDataSetChanged(); detailsChart.setVisibleXRangeMaximum(90); detailsChart.moveViewToX(pos - 91); } } else { detailsChart.clear(); detailsChart.setVisibility(View.GONE); } if (last.status == Download.Status.ERROR || last.status == Download.Status.REMOVED || last.status == Download.Status.COMPLETE) toggleNotification.setVisibility(View.GONE); else toggleNotification.setVisibility(View.VISIBLE); donutProgress.setProgress(last.getProgress()); downloadName.setText(last.getName()); if (last.status == Download.Status.ERROR) { if (last.errorMessage == null) downloadStatus.setText(String.format(Locale.getDefault(), "%s #%d", last.status.getFormal(context, true), last.errorCode)); else downloadStatus.setText(String.format(Locale.getDefault(), "%s #%d: %s", last.status.getFormal(context, true), last.errorCode, last.errorMessage)); } else { downloadStatus.setText(last.status.getFormal(context, true)); } customInfo.update(last); detailsCompletedLength.setHtml(R.string.completed_length, CommonUtils.dimensionFormatter(last.completedLength, false)); if (last.isTorrent()) { detailsUploadLength.setHtml(R.string.uploaded_length, CommonUtils.dimensionFormatter(last.uploadLength, false)); detailsUploadLength.setVisibility(View.VISIBLE); } else { detailsUploadLength.setVisibility(View.GONE); } setupActions(download); CommonUtils.setRecyclerViewTopMargin(this); }
Example 12
Source File: RangeTestFragmentView.java From EFRConnect-android with Apache License 2.0 | 4 votes |
private void setupChartView() { Resources resources = chart.getResources(); int textColor = resources.getColor(R.color.silabs_black); int axisColor = resources.getColor(R.color.silabs_black); int graphColor = resources.getColor(R.color.silabs_red); chart.getDescription().setEnabled(false); chart.getLegend().setEnabled(false); chart.setScaleEnabled(false); chart.setHighlightPerTapEnabled(false); chart.setHighlightPerDragEnabled(false); chart.setDoubleTapToZoomEnabled(false); chart.getAxisRight().setEnabled(false); chart.getAxisLeft().setValueFormatter(new YAxisValueFormatter()); chart.getAxisLeft().setTextSize(10f); chart.getAxisLeft().setTextColor(textColor); chart.getAxisLeft().setAxisMinimum(-100); chart.getAxisLeft().setAxisMaximum(25); chart.getAxisLeft().setGranularity(25); chart.getAxisLeft().setDrawGridLines(false); chart.getAxisLeft().setDrawAxisLine(true); chart.getAxisLeft().setAxisLineWidth(0.5f); chart.getAxisLeft().setAxisLineColor(axisColor); chart.setRendererLeftYAxis(new YAxisArrowRenderer(chart.getViewPortHandler(), chart.getAxisLeft(), chart.getRendererLeftYAxis().getTransformer())); chart.getXAxis().setDrawGridLines(false); chart.getXAxis().setDrawAxisLine(false); chart.getXAxis().setAxisMinimum(0); chart.getXAxis().setAxisMaximum(50); chart.getXAxis().setValueFormatter(new XAxisValueFormatter()); chart.setMinOffset(0); chart.setExtraOffsets(-4f, 0, 4f, 4f); chart.getAxisLeft().addLimitLine(createLimitLine(0, axisColor)); chart.getAxisLeft().addLimitLine(createDashLine(-100, axisColor)); chart.getAxisLeft().addLimitLine(createDashLine(-75, axisColor)); chart.getAxisLeft().addLimitLine(createDashLine(-50, axisColor)); chart.getAxisLeft().addLimitLine(createDashLine(-25, axisColor)); chart.getAxisLeft().addLimitLine(createDashLine(25, axisColor)); LineData chartData = createChartData(graphColor); chart.setData(chartData); chartDataSet.notifyDataSetChanged(); chartData.notifyDataChanged(); chart.notifyDataSetChanged(); chart.invalidate(); }
Example 13
Source File: TickChart.java From android-kline with Apache License 2.0 | 4 votes |
public void addEntry(HisData hisData) { hisData = DataUtils.calculateHisData(hisData, mList); LineData data = mChart.getData(); if (data != null) { ILineDataSet setSell = data.getDataSetByIndex(DATA_SET_PRICE); if (setSell == null) { setSell = createSet(TYPE_FULL); data.addDataSet(setSell); } ILineDataSet aveSet = data.getDataSetByIndex(DATA_SET_AVE); if (aveSet == null) { aveSet = createSet(DATA_SET_AVE); data.addDataSet(aveSet); } int index = mList.indexOf(hisData); if (index >= 0) { mList.remove(hisData); data.removeEntry(index, DATA_SET_PRICE); data.removeEntry(index, DATA_SET_AVE); } mList.add(hisData); float price = (float) hisData.getClose(); data.addEntry(new Entry(setSell.getEntryCount(), price), DATA_SET_PRICE); data.addEntry(new Entry(setSell.getEntryCount(), (float) hisData.getAvePrice()), DATA_SET_AVE); ILineDataSet paddingSet = data.getDataSetByIndex(DATA_SET_PADDING); if (paddingSet == null) { paddingSet = createSet(TYPE_DASHED); data.addDataSet(paddingSet); } int count = paddingSet.getEntryCount(); if (count > PADDING_COUNT && index < 0) { count--; } paddingSet.clear(); for (int i = 0; i < count; i++) { paddingSet.addEntry(new Entry(setSell.getEntryCount() + i, price)); } Highlight chartHighlighter = new Highlight(setSell.getEntryCount() + paddingSet.getEntryCount(), price, DATA_SET_PADDING); mChart.highlightValue(chartHighlighter); data.notifyDataChanged(); mChart.notifyDataSetChanged(); mChart.invalidate(); } }