Search in sources :

Example 1 with CandleEntry

use of com.github.mikephil.charting.data.CandleEntry in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method generateCandleData.

protected CandleData generateCandleData() {
    CandleData d = new CandleData();
    ArrayList<CandleEntry> entries = new ArrayList<CandleEntry>();
    for (int index = 0; index < itemcount; 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;
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) ArrayList(java.util.ArrayList) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet)

Example 2 with CandleEntry

use of com.github.mikephil.charting.data.CandleEntry in project MPAndroidChart by PhilJay.

the class MyMarkerView method refreshContent.

// callbacks everytime the MarkerView is redrawn, can be used to update the
// content (user-interface)
@Override
public void refreshContent(Entry e, Highlight highlight) {
    if (e instanceof CandleEntry) {
        CandleEntry ce = (CandleEntry) e;
        tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
    } else {
        tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
    }
    super.refreshContent(e, highlight);
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry)

Example 3 with CandleEntry

use of com.github.mikephil.charting.data.CandleEntry in project MPAndroidChart by PhilJay.

the class CandleStickChartRenderer method drawValues.

@Override
public void drawValues(Canvas c) {
    // if values are drawn
    if (isDrawingValuesAllowed(mChart)) {
        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);
            Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
            mXBounds.set(mChart, dataSet);
            float[] positions = trans.generateTransformedValuesCandle(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
            float yOffset = Utils.convertDpToPixel(5f);
            MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
            iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
            iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
            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 = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
                if (dataSet.isDrawValuesEnabled()) {
                    drawValue(c, dataSet.getValueFormatter(), entry.getHigh(), entry, i, x, y - yOffset, dataSet.getValueTextColor(j / 2));
                }
                if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
                    Drawable icon = entry.getIcon();
                    Utils.drawImage(c, icon, (int) (x + iconsOffset.x), (int) (y + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
                }
            }
            MPPointF.recycleInstance(iconsOffset);
        }
    }
}
Also used : ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) Transformer(com.github.mikephil.charting.utils.Transformer) CandleEntry(com.github.mikephil.charting.data.CandleEntry) MPPointF(com.github.mikephil.charting.utils.MPPointF) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint)

Example 4 with CandleEntry

use of com.github.mikephil.charting.data.CandleEntry in project carat by amplab.

the class CandleStickChart method drawData.

@Override
protected void drawData() {
    ArrayList<CandleDataSet> dataSets = mData.getDataSets();
    // pre allocate
    float[] shadowPoints = new float[4];
    float[] bodyPoints = new float[4];
    for (int i = 0; i < mData.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);
            }
        }
    }
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet) Paint(android.graphics.Paint)

Example 5 with CandleEntry

use of com.github.mikephil.charting.data.CandleEntry in project MPAndroidChart by PhilJay.

the class CandleStickChartActivity method onProgressChanged.

@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, getResources().getDrawable(R.drawable.star)));
    }
    CandleDataSet set1 = new CandleDataSet(yVals1, "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);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : CandleEntry(com.github.mikephil.charting.data.CandleEntry) CandleData(com.github.mikephil.charting.data.CandleData) ArrayList(java.util.ArrayList) CandleDataSet(com.github.mikephil.charting.data.CandleDataSet) ICandleDataSet(com.github.mikephil.charting.interfaces.datasets.ICandleDataSet) Paint(android.graphics.Paint)

Aggregations

CandleEntry (com.github.mikephil.charting.data.CandleEntry)9 Paint (android.graphics.Paint)5 CandleDataSet (com.github.mikephil.charting.data.CandleDataSet)4 CandleData (com.github.mikephil.charting.data.CandleData)3 ICandleDataSet (com.github.mikephil.charting.interfaces.datasets.ICandleDataSet)3 Transformer (com.github.mikephil.charting.utils.Transformer)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 MPPointD (com.github.mikephil.charting.utils.MPPointD)1 MPPointF (com.github.mikephil.charting.utils.MPPointF)1