com.github.mikephil.charting.data.CandleDataSet Java Examples
The following examples show how to use
com.github.mikephil.charting.data.CandleDataSet.
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: KLineDataManage.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private CandleDataSet setACandle(ArrayList<CandleEntry> candleEntries) { CandleDataSet candleDataSet = new CandleDataSet(candleEntries, "蜡烛线"); candleDataSet.setDrawHorizontalHighlightIndicator(true); candleDataSet.setHighlightEnabled(true); candleDataSet.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color)); candleDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); candleDataSet.setDecreasingColor(ContextCompat.getColor(mContext, R.color.down_color)); candleDataSet.setDecreasingPaintStyle(Paint.Style.FILL); candleDataSet.setIncreasingColor(ContextCompat.getColor(mContext, R.color.up_color)); candleDataSet.setIncreasingPaintStyle(Paint.Style.FILL); candleDataSet.setNeutralColor(ContextCompat.getColor(mContext, R.color.equal_color)); candleDataSet.setShadowColorSameAsCandle(true); candleDataSet.setValueTextSize(10); candleDataSet.setDrawValues(true); return candleDataSet; }
Example #2
Source File: KLineDataManage.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private CandleDataSet setBOLLCandle(ArrayList<CandleEntry> candleEntries) { CandleDataSet candleDataSet = new CandleDataSet(candleEntries, "BOLL叠加蜡烛线"); candleDataSet.setDrawHorizontalHighlightIndicator(false); candleDataSet.setHighlightEnabled(true); candleDataSet.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color)); candleDataSet.setAxisDependency(YAxis.AxisDependency.LEFT); candleDataSet.setDecreasingColor(ContextCompat.getColor(mContext, R.color.down_color)); candleDataSet.setDecreasingPaintStyle(Paint.Style.FILL); candleDataSet.setIncreasingColor(ContextCompat.getColor(mContext, R.color.up_color)); candleDataSet.setIncreasingPaintStyle(Paint.Style.FILL); candleDataSet.setNeutralColor(ContextCompat.getColor(mContext, R.color.equal_color)); candleDataSet.setDrawValues(false); candleDataSet.setDrawIcons(false); candleDataSet.setShowCandleBar(false); return candleDataSet; }
Example #3
Source File: CombinedChartActivity.java From Stayfit with Apache License 2.0 | 6 votes |
protected CandleData generateCandleData() { CandleData d = new CandleData(); ArrayList<CandleEntry> entries = new ArrayList<CandleEntry>(); for (int index = 0; index < itemcount; index++) entries.add(new CandleEntry(index, 20f, 10f, 13f, 17f)); CandleDataSet set = new CandleDataSet(entries, "Candle DataSet"); set.setColor(Color.rgb(80, 80, 80)); set.setBarSpace(0.3f); set.setValueTextSize(10f); set.setDrawValues(false); d.addDataSet(set); return d; }
Example #4
Source File: CombinedChartActivity.java From StockChart-MPAndroidChart with MIT License | 6 votes |
private CandleData generateCandleData() { CandleData d = new CandleData(); ArrayList<CandleEntry> entries = new ArrayList<>(); for (int index = 0; index < count; index += 2) entries.add(new CandleEntry(index + 1f, 90, 70, 85, 75f)); CandleDataSet set = new CandleDataSet(entries, "Candle DataSet"); set.setDecreasingColor(Color.rgb(142, 150, 175)); set.setShadowColor(Color.DKGRAY); set.setBarSpace(0.3f); set.setValueTextSize(10f); set.setDrawValues(false); d.addDataSet(set); return d; }
Example #5
Source File: KlineFragment.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
/** * date: 7/9/17 * author: chenli * description: 生成蜡烛图数据 */ private CandleData generateCandleData(List<CandleEntry> candleEntries) { CandleDataSet set = new CandleDataSet(candleEntries, ""); set.setAxisDependency(YAxis.AxisDependency.LEFT); set.setShadowWidth(0.7f); set.setDecreasingColor(mDecreasingColor); set.setDecreasingPaintStyle(Paint.Style.FILL); set.setIncreasingColor(mIncreasingColor); set.setIncreasingPaintStyle(Paint.Style.STROKE); set.setNeutralColor(mHighlightColor); set.setShadowColorSameAsCandle(true); set.setHighlightLineWidth(0.7f); set.setHighLightColor(mHighlightColor); set.setDrawValues(true); set.setValueTextColor(Color.RED); set.setValueTextSize(9f); set.setDrawIcons(false); set.setValueFormatter(new TopChartLeftYAxisValueFormatter()); CandleData candleData = new CandleData(); candleData.addDataSet(set); return candleData; }
Example #6
Source File: KLineView.java From android-kline with Apache License 2.0 | 6 votes |
@android.support.annotation.NonNull public CandleDataSet setKLine(int type, ArrayList<CandleEntry> lineEntries) { CandleDataSet set = new CandleDataSet(lineEntries, "KLine" + type); set.setDrawIcons(false); set.setAxisDependency(YAxis.AxisDependency.LEFT); set.setShadowColor(Color.DKGRAY); set.setShadowWidth(0.75f); set.setDecreasingColor(mDecreasingColor); set.setDecreasingPaintStyle(Paint.Style.FILL); set.setShadowColorSameAsCandle(true); set.setIncreasingColor(mIncreasingColor); set.setIncreasingPaintStyle(Paint.Style.FILL); set.setNeutralColor(ContextCompat.getColor(getContext(), R.color.increasing_color)); set.setDrawValues(true); set.setValueTextSize(10); set.setHighlightEnabled(true); if (type != NORMAL_LINE) { set.setVisible(false); } return set; }
Example #7
Source File: CandleStickChartRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void drawData(Canvas c) { CandleData candleData = mChart.getCandleData(); for (CandleDataSet set : candleData.getDataSets()) { if (set.isVisible() && set.getEntryCount() > 0) drawDataSet(c, set); } }
Example #8
Source File: CandleStickChartManager.java From react-native-mp-android-chart with MIT License | 5 votes |
@Override void dataSetConfig(IDataSet<CandleEntry> dataSet, ReadableMap config) { CandleDataSet candleDataSet = (CandleDataSet) dataSet; ChartDataSetConfigUtils.commonConfig(candleDataSet, config); ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(candleDataSet, config); ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(candleDataSet, config); // CandleDataSet only config if (BridgeUtils.validate(config, ReadableType.Number, "barSpace")) { candleDataSet.setBarSpace((float) config.getDouble("barSpace")); } if (BridgeUtils.validate(config, ReadableType.Number, "shadowWidth")) { candleDataSet.setShadowWidth((float) config.getDouble("shadowWidth")); } if (BridgeUtils.validate(config, ReadableType.String, "shadowColor")) { candleDataSet.setShadowColor(Color.parseColor(config.getString("shadowColor"))); } if (BridgeUtils.validate(config, ReadableType.Boolean, "shadowColorSameAsCandle")) { candleDataSet.setShadowColorSameAsCandle(config.getBoolean("shadowColorSameAsCandle")); } if (BridgeUtils.validate(config, ReadableType.String, "neutralColor")) { candleDataSet.setNeutralColor(Color.parseColor(config.getString("neutralColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "decreasingColor")) { candleDataSet.setDecreasingColor(Color.parseColor(config.getString("decreasingColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "decreasingPaintStyle")) { candleDataSet.setDecreasingPaintStyle(Paint.Style.valueOf(config.getString("decreasingPaintStyle").toUpperCase())); } if (BridgeUtils.validate(config, ReadableType.String, "increasingColor")) { candleDataSet.setIncreasingColor(Color.parseColor(config.getString("increasingColor"))); } if (BridgeUtils.validate(config, ReadableType.String, "increasingPaintStyle")) { candleDataSet.setIncreasingPaintStyle(Paint.Style.valueOf(config.getString("increasingPaintStyle").toUpperCase())); } }
Example #9
Source File: CandleStickChartRenderer.java From iMoney with Apache License 2.0 | 5 votes |
@Override public void initBuffers() { CandleData candleData = mChart.getCandleData(); mShadowBuffers = new CandleShadowBuffer[candleData.getDataSetCount()]; mBodyBuffers = new CandleBodyBuffer[candleData.getDataSetCount()]; for (int i = 0; i < mShadowBuffers.length; i++) { CandleDataSet set = candleData.getDataSetByIndex(i); mShadowBuffers[i] = new CandleShadowBuffer(set.getValueCount() * 4); mBodyBuffers[i] = new CandleBodyBuffer(set.getValueCount() * 4); } }
Example #10
Source File: CandleStickChartActivity.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress = (seekBarX.getProgress()); tvX.setText(String.valueOf(progress)); tvY.setText(String.valueOf(seekBarY.getProgress())); chart.resetTracking(); ArrayList<CandleEntry> values = new ArrayList<>(); for (int i = 0; i < progress; i++) { float multi = (seekBarY.getProgress() + 1); float val = (float) (Math.random() * 40) + multi; float high = (float) (Math.random() * 9) + 8f; float low = (float) (Math.random() * 9) + 8f; float open = (float) (Math.random() * 6) + 1f; float close = (float) (Math.random() * 6) + 1f; boolean even = i % 2 == 0; values.add(new CandleEntry( i, val + high, val - low, even ? val + open : val - open, even ? val - close : val + close, getResources().getDrawable(R.drawable.star) )); } CandleDataSet set1 = new CandleDataSet(values, "Data Set"); set1.setDrawIcons(false); set1.setAxisDependency(AxisDependency.LEFT); // set1.setColor(Color.rgb(80, 80, 80)); set1.setShadowColor(Color.DKGRAY); set1.setShadowWidth(0.7f); set1.setDecreasingColor(Color.RED); set1.setDecreasingPaintStyle(Paint.Style.FILL); set1.setIncreasingColor(Color.rgb(122, 242, 84)); set1.setIncreasingPaintStyle(Paint.Style.STROKE); set1.setNeutralColor(Color.BLUE); //set1.setHighlightLineWidth(1f); CandleData data = new CandleData(set1); chart.setData(data); chart.invalidate(); }
Example #11
Source File: KLineDataManage.java From StockChart-MPAndroidChart with MIT License | 4 votes |
public CandleDataSet getBollCandleDataSet() { return bollCandleDataSet; }
Example #12
Source File: CandleStickChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { int prog = (mSeekBarX.getProgress() + 1); tvX.setText("" + prog); tvY.setText("" + (mSeekBarY.getProgress())); mChart.resetTracking(); ArrayList<CandleEntry> yVals1 = new ArrayList<CandleEntry>(); for (int i = 0; i < prog; i++) { float mult = (mSeekBarY.getProgress() + 1); float val = (float) (Math.random() * 40) + mult; float high = (float) (Math.random() * 9) + 8f; float low = (float) (Math.random() * 9) + 8f; float open = (float) (Math.random() * 6) + 1f; float close = (float) (Math.random() * 6) + 1f; boolean even = i % 2 == 0; yVals1.add(new CandleEntry(i, val + high, val - low, even ? val + open : val - open, even ? val - close : val + close)); } ArrayList<String> xVals = new ArrayList<String>(); for (int i = 0; i < prog; i++) { xVals.add("" + (1990 + i)); } CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set"); set1.setAxisDependency(AxisDependency.LEFT); // set1.setColor(Color.rgb(80, 80, 80)); set1.setShadowColor(Color.DKGRAY); set1.setShadowWidth(0.7f); set1.setDecreasingColor(Color.RED); set1.setDecreasingPaintStyle(Paint.Style.FILL); set1.setIncreasingColor(Color.rgb(122, 242, 84)); set1.setIncreasingPaintStyle(Paint.Style.STROKE); set1.setNeutralColor(Color.BLUE); //set1.setHighlightLineWidth(1f); CandleData data = new CandleData(xVals, set1); mChart.setData(data); mChart.invalidate(); }
Example #13
Source File: CandleStickChartManager.java From react-native-mp-android-chart with MIT License | 4 votes |
@Override IDataSet createDataSet(ArrayList<CandleEntry> entries, String label) { return new CandleDataSet(entries, label); }
Example #14
Source File: KLineDataManage.java From StockChart-MPAndroidChart with MIT License | 4 votes |
public CandleDataSet getCandleDataSet() { return candleDataSet; }
Example #15
Source File: CandleStickChart.java From Notification-Analyser with MIT License | 4 votes |
@Override protected void drawData() { ArrayList<CandleDataSet> dataSets = mCurrentData.getDataSets(); // pre allocate float[] shadowPoints = new float[4]; float[] bodyPoints = new float[4]; for (int i = 0; i < mCurrentData.getDataSetCount(); i++) { CandleDataSet dataSet = dataSets.get(i); ArrayList<CandleEntry> entries = dataSet.getYVals(); mRenderPaint.setStrokeWidth(dataSet.getShadowWidth()); for (int j = 0; j < entries.size() * mPhaseX; j++) { // get the color that is specified for this position from // the DataSet, this will reuse colors, if the index is out // of bounds mRenderPaint.setColor(dataSet.getColor(j)); // get the entry CandleEntry e = entries.get(j); // transform the entries values for shadow and body transformShadow(shadowPoints, e); transformBody(bodyPoints, e, dataSet.getBodySpace()); float xShadow = shadowPoints[0]; float leftBody = bodyPoints[0]; float rightBody = bodyPoints[2]; float high = shadowPoints[1]; float low = shadowPoints[3]; float open = bodyPoints[1]; float close = bodyPoints[3]; if (isOffContentRight(leftBody)) break; // make sure the lines don't do shitty things outside bounds if (isOffContentLeft(rightBody) && isOffContentTop(low) && isOffContentBottom(high)) continue; // draw the shadow mDrawCanvas.drawLine(xShadow, low, xShadow, high, mRenderPaint); // decide weather the body is hollow or filled if (open > close) { mRenderPaint.setStyle(Paint.Style.FILL); // draw the body mDrawCanvas.drawRect(leftBody, close, rightBody, open, mRenderPaint); } else { mRenderPaint.setStyle(Paint.Style.STROKE); // draw the body mDrawCanvas.drawRect(leftBody, open, rightBody, close, mRenderPaint); } } } }
Example #16
Source File: CandleStickChart.java From Notification-Analyser with MIT License | 4 votes |
@Override protected void drawHighlights() { for (int i = 0; i < mIndicesToHightlight.length; i++) { int xIndex = mIndicesToHightlight[i].getXIndex(); // get the // x-position CandleDataSet set = mOriginalData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex()); if (set == null) continue; mHighlightPaint.setColor(set.getHighLightColor()); CandleEntry e = set.getEntryForXIndex(xIndex); if(e == null) continue; float low = e.getLow() * mPhaseY; float high = e.getHigh() * mPhaseY; float[] vertPts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, xIndex + 1f, mYChartMax, xIndex + 1f, mYChartMin }; float[] horPts = new float[] { 0, low, mDeltaX, low, 0, high, mDeltaX, high }; transformPointArray(vertPts); transformPointArray(horPts); // draw the vertical highlight lines mDrawCanvas.drawLines(vertPts, mHighlightPaint); // draw the horizontal highlight lines mDrawCanvas.drawLines(horPts, mHighlightPaint); } }
Example #17
Source File: CandleStickChartRenderer.java From iMoney with Apache License 2.0 | 3 votes |
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { for (int i = 0; i < indices.length; i++) { int xIndex = indices[i].getXIndex(); // get the // x-position CandleDataSet set = mChart.getCandleData().getDataSetByIndex( indices[i].getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; CandleEntry e = set.getEntryForXIndex(xIndex); if (e == null || e.getXIndex() != xIndex) continue; float low = e.getLow() * mAnimator.getPhaseY(); float high = e.getHigh() * mAnimator.getPhaseY(); float y = (low + high) / 2f; float min = mChart.getYChartMin(); float max = mChart.getYChartMax(); float[] pts = new float[] { xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } }
Example #18
Source File: CandleStickChartRenderer.java From iMoney with Apache License 2.0 | 2 votes |
@Override public void drawValues(Canvas c) { // if values are drawn if (mChart.getCandleData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) { List<CandleDataSet> dataSets = mChart.getCandleData().getDataSets(); for (int i = 0; i < dataSets.size(); i++) { CandleDataSet dataSet = dataSets.get(i); if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); List<CandleEntry> entries = dataSet.getYVals(); int minx = Math.max(mMinX, 0); int maxx = Math.min(mMaxX + 1, entries.size()); float[] positions = trans.generateTransformedValuesCandle( entries, mAnimator.getPhaseX(), mAnimator.getPhaseY(), minx, maxx); float yOffset = Utils.convertDpToPixel(5f); for (int j = 0; j < positions.length; j += 2) { float x = positions[j]; float y = positions[j + 1]; if (!mViewPortHandler.isInBoundsRight(x)) break; if (!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y)) continue; CandleEntry entry = entries.get(j / 2 + minx); drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset); } } } }