com.github.mikephil.charting.data.CombinedData Java Examples
The following examples show how to use
com.github.mikephil.charting.data.CombinedData.
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: KLineChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 副图指标成交量 */ public void setVolumeToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setAxisMinimum(0); axisLeftBar.setValueFormatter(new VolFormatter(mContext, kLineData.getAssetId())); CombinedData combinedData = barChart.getData(); combinedData.setData(new BarData(kLineData.getVolumeDataSet())); combinedData.setData(new LineData()); barChart.notifyDataSetChanged(); barChart.animateY(1000); } }
Example #2
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 6 votes |
/** * according to the price to refresh the last data of the chart */ public void refreshData(float price) { if (price <= 0 || price == mLastPrice) { return; } mLastPrice = price; CombinedData data = mChartPrice.getData(); if (data == null) return; LineData lineData = data.getLineData(); if (lineData != null) { ILineDataSet set = lineData.getDataSetByIndex(0); if (set.removeLast()) { set.addEntry(new Entry(set.getEntryCount(), price)); } } mChartPrice.notifyDataSetChanged(); mChartPrice.invalidate(); }
Example #3
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 6 votes |
private void initChartVolumeData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getVol(), t)); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); mChartVolume.setData(combinedData); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); mChartVolume.moveViewToX(combinedData.getEntryCount()); }
Example #4
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 6 votes |
/** * 动态更新最后一点数据 最新数据集 * * @param kLineData */ public void dynamicsUpdateOne(KLineDataManage kLineData) { int size = kLineData.getKLineDatas().size(); int i = size - 1; CombinedData candleChartData = candleChart.getData(); CandleData candleData = candleChartData.getCandleData(); ICandleDataSet candleDataSet = candleData.getDataSetByIndex(0); candleDataSet.removeEntry(i); candleDataSet.addEntry(new CandleEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getHigh(), (float) kLineData.getKLineDatas().get(i).getLow(), (float) kLineData.getKLineDatas().get(i).getOpen(), (float) kLineData.getKLineDatas().get(i).getClose())); if (chartType1 == 1) {//副图是成交量 CombinedData barChartData = barChart.getData(); IBarDataSet barDataSet = barChartData.getBarData().getDataSetByIndex(0); barDataSet.removeEntry(i); float color = kLineData.getKLineDatas().get(i).getOpen() == kLineData.getKLineDatas().get(i).getClose()?0f:kLineData.getKLineDatas().get(i).getOpen() > kLineData.getKLineDatas().get(i).getClose() ? -1f : 1f; BarEntry barEntry = new BarEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getVolume(), color); barDataSet.addEntry(barEntry); } else {//副图是其他技术指标 doBarChartSwitch(chartType1); } candleChart.notifyDataSetChanged(); barChart.notifyDataSetChanged(); candleChart.invalidate(); barChart.invalidate(); }
Example #5
Source File: CombinedChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #6
Source File: AppCombinedChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof AppLineChartRenderer) data = ((AppLineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #7
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartKdjData() { ArrayList<Entry> kEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> dEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> jEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT); for (int i = 0; i < mData.size(); i++) { kEntries.add(new Entry(i, (float) mData.get(i).getK())); dEntries.add(new Entry(i, (float) mData.get(i).getD())); jEntries.add(new Entry(i, (float) mData.get(i).getJ())); } if (!mData.isEmpty() && mData.size() < MAX_COUNT) { for (int i = mData.size(); i < MAX_COUNT; i++) { paddingEntries.add(new Entry(i, (float) mData.get(mData.size() - 1).getK())); } } ArrayList<ILineDataSet> sets = new ArrayList<>(); sets.add(setLine(K, kEntries)); sets.add(setLine(D, dEntries)); sets.add(setLine(J, jEntries)); sets.add(setLine(INVISIABLE_LINE, paddingEntries)); LineData lineData = new LineData(sets); CombinedData combinedData = new CombinedData(); combinedData.setData(lineData); mChartKdj.setData(combinedData); mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartKdj.notifyDataSetChanged(); moveToLast(mChartKdj); }
Example #8
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartMacdData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); ArrayList<Entry> difEntries = new ArrayList<>(); ArrayList<Entry> deaEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getMacd())); difEntries.add(new Entry(i, (float) t.getDif())); deaEntries.add(new Entry(i, (float) t.getDea())); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); LineData lineData = new LineData(setLine(DIF, difEntries), setLine(DEA, deaEntries)); combinedData.setData(lineData); mChartMacd.setData(combinedData); mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartMacd.notifyDataSetChanged(); // mChartMacd.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartMacd); }
Example #9
Source File: KLineView.java From android-kline with Apache License 2.0 | 5 votes |
private void initChartVolumeData() { ArrayList<BarEntry> barEntries = new ArrayList<>(); ArrayList<BarEntry> paddingEntries = new ArrayList<>(); for (int i = 0; i < mData.size(); i++) { HisData t = mData.get(i); barEntries.add(new BarEntry(i, (float) t.getVol(), t)); } int maxCount = MAX_COUNT; if (!mData.isEmpty() && mData.size() < maxCount) { for (int i = mData.size(); i < maxCount; i++) { paddingEntries.add(new BarEntry(i, 0)); } } BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE)); barData.setBarWidth(0.75f); CombinedData combinedData = new CombinedData(); combinedData.setData(barData); mChartVolume.setData(combinedData); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); // mChartVolume.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartVolume); }
Example #10
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 5 votes |
public void addData(HisData hisData) { hisData = DataUtils.calculateHisData(hisData, mData); CombinedData combinedData = mChartPrice.getData(); LineData priceData = combinedData.getLineData(); ILineDataSet priceSet = priceData.getDataSetByIndex(0); ILineDataSet aveSet = priceData.getDataSetByIndex(1); IBarDataSet volSet = mChartVolume.getData().getBarData().getDataSetByIndex(0); if (mData.contains(hisData)) { int index = mData.indexOf(hisData); priceSet.removeEntry(index); aveSet.removeEntry(index); volSet.removeEntry(index); mData.remove(index); } mData.add(hisData); priceSet.addEntry(new Entry(priceSet.getEntryCount(), (float) hisData.getClose())); aveSet.addEntry(new Entry(aveSet.getEntryCount(), (float) hisData.getAvePrice())); volSet.addEntry(new BarEntry(volSet.getEntryCount(), hisData.getVol(), hisData)); mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 1.5f); mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 1.5f); mChartPrice.notifyDataSetChanged(); mChartPrice.invalidate(); mChartVolume.notifyDataSetChanged(); mChartVolume.invalidate(); setDescription(mChartVolume, "成交量 " + hisData.getVol()); }
Example #11
Source File: AppCombinedChart.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void setData(CombinedData data) { try { super.setData(data); }catch (ClassCastException e) { // ignore } ((AppCombinedChartRenderer) mRenderer).createRenderers(); mRenderer.initBuffers(); }
Example #12
Source File: CombinedChartActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_combined); mChart = (CombinedChart) findViewById(R.id.chart1); mChart.setDescription(""); mChart.setBackgroundColor(Color.WHITE); mChart.setDrawGridBackground(false); mChart.setDrawBarShadow(false); // draw bars behind lines mChart.setDrawOrder(new DrawOrder[] { DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setDrawGridLines(false); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTH_SIDED); CombinedData data = new CombinedData(mMonths); data.setData(generateLineData()); data.setData(generateBarData()); // data.setData(generateBubbleData()); // data.setData(generateScatterData()); // data.setData(generateCandleData()); mChart.setData(data); mChart.invalidate(); }
Example #13
Source File: CombinedChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); ArrayList<Highlight> dataIndices = new ArrayList<>(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) dataIndices.add(h); } renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()])); } }
Example #14
Source File: CombinedChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) return; for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) data = ((BarChartRenderer)renderer).mChart.getBarData(); else if (renderer instanceof LineChartRenderer) data = ((LineChartRenderer)renderer).mChart.getLineData(); else if (renderer instanceof CandleStickChartRenderer) data = ((CandleStickChartRenderer)renderer).mChart.getCandleData(); else if (renderer instanceof ScatterChartRenderer) data = ((ScatterChartRenderer)renderer).mChart.getScatterData(); else if (renderer instanceof BubbleChartRenderer) data = ((BubbleChartRenderer)renderer).mChart.getBubbleData(); int dataIndex = data == null ? -1 : ((CombinedData)chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) mHighlightBuffer.add(h); } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #15
Source File: CombinedChart.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void setData(CombinedData data) { super.setData(data); setHighlighter(new CombinedHighlighter(this, this)); ((CombinedChartRenderer)mRenderer).createRenderers(); mRenderer.initBuffers(); }
Example #16
Source File: CombinedHighlighter.java From NetKnight with Apache License 2.0 | 5 votes |
/** * Returns a list of SelectionDetail object corresponding to the given xIndex. * * @param xIndex * @return */ @Override protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) { List<SelectionDetail> vals = new ArrayList<SelectionDetail>(); float[] pts = new float[2]; CombinedData data = (CombinedData) mChart.getData(); // get all chartdata objects List<ChartData> dataObjects = data.getAllData(); for (int i = 0; i < dataObjects.size(); i++) { for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) { IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j); // dont include datasets that cannot be highlighted if (!dataSet.isHighlightEnabled()) continue; // extract all y-values from all DataSets at the given x-index final float yVals[] = dataSet.getYValsForXIndex(xIndex); for (float yVal : yVals) { pts[1] = yVal; mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts); if (!Float.isNaN(pts[1])) { vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet)); } } } } return vals; }
Example #17
Source File: CombinedChart.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void setData(CombinedData data) { super.setData(data); setHighlighter(new CombinedHighlighter(this, this)); ((CombinedChartRenderer)mRenderer).createRenderers(); mRenderer.initBuffers(); }
Example #18
Source File: StatisticsFragment.java From HeartBeat with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { StopWatch watch = new StopWatch(TAG, UpdateChartTask.class.getSimpleName()); mCombinedData = new CombinedData(TimeUtils.getWeekDateString()); mCombinedData.setData(getWeekEventData()); mCombinedData.setData(getWeekThoughtData()); watch.stop(); return null; }
Example #19
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 动态增加一个点数据 * * @param kLineData 最新数据集 */ public void dynamicsAddOne(KLineDataManage kLineData) { int size = kLineData.getKLineDatas().size(); CombinedData candleChartData = candleChart.getData(); CandleData candleData = candleChartData.getCandleData(); ICandleDataSet candleDataSet = candleData.getDataSetByIndex(0); int i = size - 1; candleDataSet.addEntry(new CandleEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getHigh(), (float) kLineData.getKLineDatas().get(i).getLow(), (float) kLineData.getKLineDatas().get(i).getOpen(), (float) kLineData.getKLineDatas().get(i).getClose())); kLineData.getxVals().add(DataTimeUtil.secToDate(kLineData.getKLineDatas().get(i).getDateMills())); candleChart.getXAxis().setAxisMaximum(kLineData.getKLineDatas().size() < 70 ? 70 : candleChartData.getXMax() + kLineData.getOffSet()); if (chartType1 == 1) {//副图是成交量 CombinedData barChartData = barChart.getData(); IBarDataSet barDataSet = barChartData.getBarData().getDataSetByIndex(0); if (barDataSet == null) {//当没有数据时 return; } float color = kLineData.getKLineDatas().get(i).getOpen() == kLineData.getKLineDatas().get(i).getClose()?0f:kLineData.getKLineDatas().get(i).getOpen() > kLineData.getKLineDatas().get(i).getClose() ? -1f : 1f; BarEntry barEntry = new BarEntry(i + kLineData.getOffSet(), (float) kLineData.getKLineDatas().get(i).getVolume(), color); barDataSet.addEntry(barEntry); barChart.getXAxis().setAxisMaximum(kLineData.getKLineDatas().size() < 70 ? 70 : barChartData.getXMax() + kLineData.getOffSet()); } else {//副图是其他技术指标 doBarChartSwitch(chartType1); } candleChart.notifyDataSetChanged(); barChart.notifyDataSetChanged(); if (kLineData.getKLineDatas().size() > 70) { //moveViewTo(...) 方法会自动调用 invalidate() candleChart.moveViewToX(kLineData.getKLineDatas().size() - 1); barChart.moveViewToX(kLineData.getKLineDatas().size() - 1); } else { candleChart.invalidate(); barChart.invalidate(); } }
Example #20
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标RSI */ public void setRSIToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataRSI())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example #21
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标BOLL */ public void setBOLLToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new CandleData(kLineData.getBollCandleDataSet())); combinedData.setData(new LineData(kLineData.getLineDataBOLL())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example #22
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标KDJ */ public void setKDJToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataKDJ())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example #23
Source File: KLineChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * 副图指标MACD */ public void setMACDToChart() { if (barChart != null) { if (barChart.getBarData() != null) { barChart.getBarData().clearValues(); } if (barChart.getLineData() != null) { barChart.getLineData().clearValues(); } if (barChart.getCandleData() != null) { barChart.getCandleData().clearValues(); } axisLeftBar.resetAxisMaximum(); axisLeftBar.resetAxisMinimum(); axisLeftBar.setValueFormatter(new ValueFormatter() { @Override public String getAxisLabel(float value, AxisBase axis) { return NumberUtils.keepPrecision(value, precision); } }); CombinedData combinedData = barChart.getData(); combinedData.setData(new LineData(kLineData.getLineDataMACD())); combinedData.setData(new BarData(kLineData.getBarDataMACD())); barChart.notifyDataSetChanged(); barChart.invalidate(); } }
Example #24
Source File: CombinedChartRenderer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { Chart chart = mChart.get(); if (chart == null) { return; } for (DataRenderer renderer : mRenderers) { ChartData data = null; if (renderer instanceof BarChartRenderer) { data = ((BarChartRenderer) renderer).mChart.getBarData(); } else if (renderer instanceof LineChartRenderer) { data = ((LineChartRenderer) renderer).mChart.getLineData(); } else if (renderer instanceof CandleStickChartRenderer) { data = ((CandleStickChartRenderer) renderer).mChart.getCandleData(); } else if (renderer instanceof ScatterChartRenderer) { data = ((ScatterChartRenderer) renderer).mChart.getScatterData(); } else if (renderer instanceof BubbleChartRenderer) { data = ((BubbleChartRenderer) renderer).mChart.getBubbleData(); } int dataIndex = data == null ? -1 : ((CombinedData) chart.getData()).getAllData().indexOf(data); mHighlightBuffer.clear(); for (Highlight h : indices) { if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) { mHighlightBuffer.add(h); } } renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()])); } }
Example #25
Source File: CombinedChart.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public void setData(CombinedData data) { super.setData(data); setHighlighter(new CombinedHighlighter(this, this)); ((CombinedChartRenderer)mRenderer).createRenderers(); mRenderer.initBuffers(); }
Example #26
Source File: ReportAdapter.java From privacy-friendly-interval-timer with GNU General Public License v3.0 | 4 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { switch (getItemViewType(position)) { case TYPE_CHART: ActivityChart barChartData = (ActivityChart) mItems.get(position); CombinedChartViewHolder barChartViewHolder = (CombinedChartViewHolder) holder; barChartViewHolder.mTitleTextView.setText(barChartData.getTitle()); int barChartI = 0; ArrayList<String> barChartXValues = new ArrayList<>(); Map<String, Double> barChartDataMap; String barChartLabel; if (barChartData.getDisplayedDataType() == null) { barChartDataMap = barChartData.getTime(); barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time); } else { switch (barChartData.getDisplayedDataType()) { case CALORIES: barChartDataMap = barChartData.getCalories(); barChartLabel = barChartViewHolder.context.getString(R.string.report_calories); break; case TIME: default: barChartDataMap = barChartData.getTime(); barChartLabel = barChartViewHolder.context.getString(R.string.report_workout_time); break; } } List<BarEntry> dataEntries = new ArrayList<>(); for (Map.Entry<String, Double> dataEntry : barChartDataMap.entrySet()) { barChartXValues.add(barChartI, dataEntry.getKey()); if (dataEntry.getValue() != null) { float val = dataEntry.getValue().floatValue(); dataEntries.add(new BarEntry(barChartI, val)); } barChartI++; } BarDataSet barDataSet = new BarDataSet(dataEntries, barChartLabel); String formatPattern = "###,###,##0.0"; barDataSet.setValueFormatter(new DoubleValueFormatter(formatPattern)); ArrayList<ILineDataSet> lineDataSets = new ArrayList<>(); // make sure, that the first and last entry are fully displayed Entry start = new Entry(0, 0); Entry end = new Entry(barChartI - 1, 0); LineDataSet chartLineDataSet = new LineDataSet(Arrays.asList(start, end), ""); chartLineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); chartLineDataSet.setDrawCircles(false); chartLineDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.transparent), 0); chartLineDataSet.setDrawValues(false); lineDataSets.add(chartLineDataSet); CombinedData combinedData = new CombinedData(); BarData barData = new BarData(barDataSet); barData.setBarWidth(0.5f); combinedData.setData(barData); combinedData.setData(new LineData(lineDataSets)); barDataSet.setColor(ContextCompat.getColor(barChartViewHolder.context, R.color.colorPrimary)); barChartViewHolder.mChart.setData(combinedData); barChartViewHolder.mChart.getXAxis().setValueFormatter(new ArrayListAxisValueFormatter(barChartXValues)); barChartViewHolder.mChart.invalidate(); break; case TYPE_SUMMARY: ActivitySummary summaryData = (ActivitySummary) mItems.get(position); SummaryViewHolder summaryViewHolder = (SummaryViewHolder) holder; summaryViewHolder.mTitleTextView.setText(summaryData.getTitle()); summaryViewHolder.mTimeTextView.setText(formatTime(summaryData.getTime())); summaryViewHolder.mCaloriesTextView.setText(String.valueOf(summaryData.getCalories())); break; } }
Example #27
Source File: RecordGraphFragment.java From voice-pitch-analyzer with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { CombinedChart chart = (CombinedChart) view.findViewById(R.id.recording_chart); pitchDataSet = new LineDataSet(mListener.startingPitchEntries(), getResources().getString(R.string.progress)); // generate x value strings // [1, 2, 3,... basically random numbers as the recorded pitch is based on processor speed] List<String> xVals = ChartData.generateXVals(0, pitchDataSet.getEntryCount()); chartData = new CombinedData(xVals); pitchDataSet.setColor(getResources().getColor(R.color.canvas_dark)); pitchDataSet.setDrawCircles(false); pitchDataSet.setLineWidth(2f); pitchDataSet.setDrawValues(false); pitchDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); pitchData = new LineData(xVals, pitchDataSet); chartData.setData(pitchData); genderBarData = new BarData(xVals, GraphLayout.getOverallRange(this.getContext(), xVals.size())); // Bug with chart lib that throws exception for empty bar charts so must skip adding it on init // if were coming from the live pitch graph. if (!xVals.isEmpty()) chartData.setData(genderBarData); chart.setData(chartData); chart.setDrawValueAboveBar(false); chart.setDrawOrder(new CombinedChart.DrawOrder[]{ CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.BUBBLE, CombinedChart.DrawOrder.CANDLE, CombinedChart.DrawOrder.LINE, CombinedChart.DrawOrder.SCATTER }); GraphLayout.FormatChart(chart); super.onViewCreated(view, savedInstanceState); }
Example #28
Source File: ProgressFragment.java From voice-pitch-analyzer with GNU Affero General Public License v3.0 | 4 votes |
@Override public void onViewCreated(View view, Bundle savedInstanceState) { CombinedChart chart = (CombinedChart) view.findViewById(R.id.progress_chart); this.recordings = new RecordingList(this.getContext()); if (this.recordings != null) { List<String> dates = this.recordings.getDates(); CombinedData data = new CombinedData(dates); LineDataSet dataSet = new LineDataSet(this.recordings.getGraphEntries(), getResources().getString(R.string.progress)); LineData lineData = new LineData(dates, dataSet); BarData barData = new BarData(dates, GraphLayout.getOverallRange(this.getContext(), dates.size())); dataSet.setDrawCubic(true); dataSet.enableDashedLine(10, 10, 0); dataSet.setLineWidth(3f); dataSet.setDrawValues(false); dataSet.setCircleColor(getResources().getColor(R.color.canvas_dark)); dataSet.setColor(getResources().getColor(R.color.canvas_dark)); dataSet.setCircleSize(5f); dataSet.setCubicIntensity(0.05f); dataSet.setAxisDependency(YAxis.AxisDependency.LEFT); data.setData(lineData); data.setData(barData); chart.setData(data); GraphLayout.FormatChart(chart); chart.setTouchEnabled(true); // chart.setScaleEnabled(true); chart.setPinchZoom(true); // chart.setDoubleTapToZoomEnabled(true); chart.setDrawValueAboveBar(false); chart.setDrawOrder(new DrawOrder[]{ DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); } super.onViewCreated(view, savedInstanceState); }
Example #29
Source File: CombinedChart.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override public CombinedData getCombinedData() { return mData; }
Example #30
Source File: KLineView.java From android-kline with Apache License 2.0 | 4 votes |
public void addData(HisData hisData) { hisData = DataUtils.calculateHisData(hisData, mData); CombinedData combinedData = mChartPrice.getData(); LineData priceData = combinedData.getLineData(); ILineDataSet ma5Set = priceData.getDataSetByIndex(1); ILineDataSet ma10Set = priceData.getDataSetByIndex(2); ILineDataSet ma20Set = priceData.getDataSetByIndex(3); ILineDataSet ma30Set = priceData.getDataSetByIndex(4); CandleData kData = combinedData.getCandleData(); ICandleDataSet klineSet = kData.getDataSetByIndex(0); IBarDataSet volSet = mChartVolume.getData().getBarData().getDataSetByIndex(0); IBarDataSet macdSet = mChartMacd.getData().getBarData().getDataSetByIndex(0); ILineDataSet difSet = mChartMacd.getData().getLineData().getDataSetByIndex(0); ILineDataSet deaSet = mChartMacd.getData().getLineData().getDataSetByIndex(1); LineData kdjData = mChartKdj.getData().getLineData(); ILineDataSet kSet = kdjData.getDataSetByIndex(0); ILineDataSet dSet = kdjData.getDataSetByIndex(1); ILineDataSet jSet = kdjData.getDataSetByIndex(2); if (mData.contains(hisData)) { int index = mData.indexOf(hisData); klineSet.removeEntry(index); // ma比较特殊,entry数量和k线的不一致,移除最后一个 ma5Set.removeLast(); ma10Set.removeLast(); ma20Set.removeLast(); ma30Set.removeLast(); volSet.removeEntry(index); macdSet.removeEntry(index); difSet.removeEntry(index); deaSet.removeEntry(index); kSet.removeEntry(index); dSet.removeEntry(index); jSet.removeEntry(index); mData.remove(index); } mData.add(hisData); int klineCount = klineSet.getEntryCount(); klineSet.addEntry(new CandleEntry(klineCount, (float) hisData.getHigh(), (float) hisData.getLow(), (float) hisData.getOpen(), (float) hisData.getClose())); volSet.addEntry(new BarEntry(volSet.getEntryCount(), hisData.getVol(), hisData)); macdSet.addEntry(new BarEntry(macdSet.getEntryCount(), (float) hisData.getMacd())); difSet.addEntry(new Entry(difSet.getEntryCount(), (float) hisData.getDif())); deaSet.addEntry(new Entry(deaSet.getEntryCount(), (float) hisData.getDea())); kSet.addEntry(new Entry(kSet.getEntryCount(), (float) hisData.getK())); dSet.addEntry(new Entry(dSet.getEntryCount(), (float) hisData.getD())); jSet.addEntry(new Entry(jSet.getEntryCount(), (float) hisData.getJ())); // 因为ma的数量会少,所以这里用kline的set数量作为x if (!Double.isNaN(hisData.getMa5())) { ma5Set.addEntry(new Entry(klineCount, (float) hisData.getMa5())); } if (!Double.isNaN(hisData.getMa10())) { ma10Set.addEntry(new Entry(klineCount, (float) hisData.getMa10())); } if (!Double.isNaN(hisData.getMa20())) { ma20Set.addEntry(new Entry(klineCount, (float) hisData.getMa20())); } if (!Double.isNaN(hisData.getMa30())) { ma30Set.addEntry(new Entry(klineCount, (float) hisData.getMa30())); } mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 1.5f); mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 1.5f); mChartMacd.getXAxis().setAxisMaximum(mChartMacd.getData().getXMax() + 1.5f); mChartKdj.getXAxis().setAxisMaximum(mChartKdj.getData().getXMax() + 1.5f); mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartMacd.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartKdj.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartPrice.notifyDataSetChanged(); mChartPrice.invalidate(); mChartVolume.notifyDataSetChanged(); mChartVolume.invalidate(); mChartMacd.notifyDataSetChanged(); mChartMacd.invalidate(); mChartKdj.notifyDataSetChanged(); mChartKdj.invalidate(); setDescription(mChartPrice, String.format(Locale.getDefault(), "MA5:%.2f MA10:%.2f MA20:%.2f MA30:%.2f", hisData.getMa5(), hisData.getMa10(), hisData.getMa20(), hisData.getMa30())); setDescription(mChartVolume, "成交量 " + hisData.getVol()); setDescription(mChartMacd, String.format(Locale.getDefault(), "MACD:%.2f DEA:%.2f DIF:%.2f", hisData.getMacd(), hisData.getDea(), hisData.getDif())); setDescription(mChartKdj, String.format(Locale.getDefault(), "K:%.2f D:%.2f J:%.2f", hisData.getK(), hisData.getD(), hisData.getJ())); }