com.github.mikephil.charting.interfaces.datasets.ICandleDataSet Java Examples
The following examples show how to use
com.github.mikephil.charting.interfaces.datasets.ICandleDataSet.
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: RealmDatabaseActivityCandle.java From Stayfit with Apache License 2.0 | 6 votes |
private void setData() { RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class); RealmCandleDataSet<RealmDemoData> set = new RealmCandleDataSet<RealmDemoData>(result, "high", "low", "open", "close", "xIndex"); set.setLabel("Realm Realm CandleDataSet"); set.setShadowColor(Color.DKGRAY); set.setShadowWidth(0.7f); set.setDecreasingColor(Color.RED); set.setDecreasingPaintStyle(Paint.Style.FILL); set.setIncreasingColor(Color.rgb(122, 242, 84)); set.setIncreasingPaintStyle(Paint.Style.STROKE); set.setNeutralColor(Color.BLUE); ArrayList<ICandleDataSet> dataSets = new ArrayList<ICandleDataSet>(); dataSets.add(set); // add the dataset // create a data object with the dataset list RealmCandleData data = new RealmCandleData(result, "xValue", dataSets); styleData(data); // set data mChart.setData(data); mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart); }
Example #2
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 #3
Source File: Transformer.java From android-kline with Apache License 2.0 | 5 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesCandle.length != count) { valuePointsForGenerateTransformedValuesCandle = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesCandle; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getHigh() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #4
Source File: CandleStickChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
Example #5
Source File: CandleStickChartRenderer.java From android-kline with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
Example #6
Source File: Transformer.java From Ticket-Analysis with MIT License | 5 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesCandle.length != count) { valuePointsForGenerateTransformedValuesCandle = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesCandle; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getHigh() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #7
Source File: CandleStickChartRenderer.java From Ticket-Analysis with MIT License | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
Example #8
Source File: CandleStickChartRenderer.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
Example #9
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 #10
Source File: Transformer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesCandle.length != count) { valuePointsForGenerateTransformedValuesCandle = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesCandle; for (int j = 0; j < count; j += 2) { CandleEntry e = null; try { e = data.getEntryForIndex(j / 2 + from); } catch (Exception e1) { e1.printStackTrace(); continue; } if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getHigh() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #11
Source File: CandleStickChartRenderer.java From NetKnight with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
Example #12
Source File: CandleStickChartRenderer.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (ICandleDataSet set : candleData.getDataSets()) { if (set.isVisible()) { drawDataSet(c, set); } } }
Example #13
Source File: MyCandleStickChartRenderer.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { CandleData candleData = mChart.getCandleData(); for (Highlight high : indices) { ICandleDataSet set = candleData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; CandleEntry e = set.getEntryForXValue(high.getX(), high.getY()); if (!isInBoundsX(e, set)) continue; float lowValue = e.getLow() * mAnimator.getPhaseY(); float highValue = e.getHigh() * mAnimator.getPhaseY(); MPPointD pix = mChart.getTransformer(set.getAxisDependency()) .getPixelForValues(e.getX(), (lowValue + highValue) / 2f); float xp = (float) pix.x; mHighlightPaint.setColor(set.getHighLightColor()); mHighlightPaint.setStrokeWidth(set.getHighlightLineWidth()); float xMax = mViewPortHandler.contentRight(); float contentBottom = mViewPortHandler.contentBottom(); //绘制竖线 c.drawLine(xp, 1, xp, mChart.getHeight(), mHighlightPaint); //判断是否画横线 float y = high.getDrawY(); if (y >= 0 && y <= contentBottom) {//在区域内即绘制横线 //绘制横线 c.drawLine(0, y, xMax, y, mHighlightPaint); } } }
Example #14
Source File: MyTransformer.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
public float[] generateTransformedValuesCandleLow(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesCandleLow.length != count) { valuePointsForGenerateTransformedValuesCandleLow = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesCandleLow; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getLow() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #15
Source File: Transformer.java From Stayfit with Apache License 2.0 | 4 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) Math.ceil((to - from) * phaseX) * 2; float[] valuePoints = new float[count]; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getXIndex(); valuePoints[j + 1] = e.getHigh() * phaseY; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #16
Source File: RealmCandleData.java From Stayfit with Apache License 2.0 | 4 votes |
public RealmCandleData(RealmResults<? extends RealmObject> result, String xValuesField, List<ICandleDataSet> dataSets) { super(RealmUtils.toXVals(result, xValuesField), dataSets); }
Example #17
Source File: MyCandleStickChartRenderer.java From shinny-futures-android with GNU General Public License v3.0 | 4 votes |
@Override public void drawValues(Canvas c) { List<ICandleDataSet> dataSets = mChart.getCandleData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { ICandleDataSet dataSet = dataSets.get(i); if (!shouldDrawValues(dataSet)) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); MyTransformer trans = ((CombinedChartKline) (mChart)).getTransformer(dataSet.getAxisDependency()); mXBounds.set(mChart, dataSet); float[] positions = trans.generateTransformedValuesCandle( dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float[] positionsLow = trans.generateTransformedValuesCandleLow( dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float yOffset = Utils.convertDpToPixel(5f); MyValueFormatter formatter = (MyValueFormatter) dataSet.getValueFormatter(); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); CandleEntry entryMin = dataSet.getEntryForIndex(mXBounds.min); float xMin = positionsLow[0]; float yMin = positionsLow[1]; CandleEntry entryMax = dataSet.getEntryForIndex(mXBounds.min); float xMax = positions[0]; float yMax = positions[1]; for (int j = 0; j < positions.length; j += 2) { float xHigh = positions[j]; float yHigh = positions[j + 1]; float xLow = positionsLow[j]; float yLow = positionsLow[j + 1]; if (!mViewPortHandler.isInBoundsRight(xHigh)) break; if (!mViewPortHandler.isInBoundsLeft(xHigh) || !mViewPortHandler.isInBoundsY(yHigh)) continue; if (!mViewPortHandler.isInBoundsRight(xLow)) break; if (!mViewPortHandler.isInBoundsLeft(xLow) || !mViewPortHandler.isInBoundsY(yLow)) continue; CandleEntry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); if (entry.getHigh() > entryMax.getHigh()) { entryMax = entry; xMax = xHigh; yMax = yHigh; } if (entry.getLow() < entryMin.getLow()) { entryMin = entry; xMin = xLow; yMin = yLow + yOffset; } } if (dataSet.isDrawValuesEnabled()) { drawValue(c, formatter.getCandleLabel(entryMax), xMax, yMax, ContextCompat.getColor(BaseApplication.getContext(), R.color.kline_red)); drawValue(c, formatter.getCandleLabelLow(entryMin), xMin, yMin, ContextCompat.getColor(BaseApplication.getContext(), R.color.kline_green)); } MPPointF.recycleInstance(iconsOffset); } }
Example #18
Source File: CandleStickChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.actionToggleHighlight: { if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); } break; } case R.id.actionTogglePinch: { if (mChart.isPinchZoomEnabled()) mChart.setPinchZoom(false); else mChart.setPinchZoom(true); mChart.invalidate(); break; } case R.id.actionToggleAutoScaleMinMax: { mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled()); mChart.notifyDataSetChanged(); break; } case R.id.actionToggleMakeShadowSameColorAsCandle: { for (ICandleDataSet set : mChart.getData().getDataSets()) { //TODO: set.setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle()); } mChart.invalidate(); break; } case R.id.animateX: { mChart.animateX(3000); break; } case R.id.animateY: { mChart.animateY(3000); break; } case R.id.animateXY: { mChart.animateXY(3000, 3000); break; } case R.id.actionSave: { if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) { Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!", Toast.LENGTH_SHORT).show(); } else Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT) .show(); break; } } return true; }
Example #19
Source File: CandleData.java From Stayfit with Apache License 2.0 | 4 votes |
private static List<ICandleDataSet> toList(ICandleDataSet dataSet) { List<ICandleDataSet> sets = new ArrayList<ICandleDataSet>(); sets.add(dataSet); return sets; }
Example #20
Source File: CandleData.java From NetKnight with Apache License 2.0 | 4 votes |
public CandleData(List<String> xVals, List<ICandleDataSet> dataSets) { super(xVals, dataSets); }
Example #21
Source File: CandleData.java From NetKnight with Apache License 2.0 | 4 votes |
public CandleData(String[] xVals, List<ICandleDataSet> dataSets) { super(xVals, dataSets); }
Example #22
Source File: CandleData.java From NetKnight with Apache License 2.0 | 4 votes |
public CandleData(List<String> xVals, ICandleDataSet dataSet) { super(xVals, toList(dataSet)); }
Example #23
Source File: CandleData.java From NetKnight with Apache License 2.0 | 4 votes |
public CandleData(String[] xVals, ICandleDataSet dataSet) { super(xVals, toList(dataSet)); }
Example #24
Source File: CandleData.java From NetKnight with Apache License 2.0 | 4 votes |
private static List<ICandleDataSet> toList(ICandleDataSet dataSet) { List<ICandleDataSet> sets = new ArrayList<ICandleDataSet>(); sets.add(dataSet); return sets; }
Example #25
Source File: RealmCandleData.java From NetKnight with Apache License 2.0 | 4 votes |
public RealmCandleData(RealmResults<? extends RealmObject> result, String xValuesField, List<ICandleDataSet> dataSets) { super(RealmUtils.toXVals(result, xValuesField), dataSets); }
Example #26
Source File: CandleStickChartRenderer.java From NetKnight with Apache License 2.0 | 4 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { CandleData candleData = mChart.getCandleData(); for (Highlight high : indices) { final int minDataSetIndex = high.getDataSetIndex() == -1 ? 0 : high.getDataSetIndex(); final int maxDataSetIndex = high.getDataSetIndex() == -1 ? candleData.getDataSetCount() : (high.getDataSetIndex() + 1); if (maxDataSetIndex - minDataSetIndex < 1) continue; for (int dataSetIndex = minDataSetIndex; dataSetIndex < maxDataSetIndex; dataSetIndex++) { int xIndex = high.getXIndex(); // get the // x-position ICandleDataSet set = mChart.getCandleData().getDataSetByIndex(dataSetIndex); if (set == null || !set.isHighlightEnabled()) continue; CandleEntry e = set.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) continue; float lowValue = e.getLow() * mAnimator.getPhaseY(); float highValue = e.getHigh() * mAnimator.getPhaseY(); float y = (lowValue + highValue) / 2f; float[] pts = new float[]{ xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } } }
Example #27
Source File: Transformer.java From NetKnight with Apache License 2.0 | 4 votes |
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the CANDLESTICKCHART. * * @param data * @return */ public float[] generateTransformedValuesCandle(ICandleDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) Math.ceil((to - from) * phaseX) * 2; float[] valuePoints = new float[count]; for (int j = 0; j < count; j += 2) { CandleEntry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getXIndex(); valuePoints[j + 1] = e.getHigh() * phaseY; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
Example #28
Source File: CandleData.java From android-kline with Apache License 2.0 | 4 votes |
public CandleData(ICandleDataSet... dataSets) { super(dataSets); }
Example #29
Source File: CandleData.java From StockChart-MPAndroidChart with MIT License | 4 votes |
public CandleData(List<ICandleDataSet> dataSets) { super(dataSets); }
Example #30
Source File: CandleData.java From StockChart-MPAndroidChart with MIT License | 4 votes |
public CandleData(ICandleDataSet... dataSets) { super(dataSets); }