Search in sources :

Example 1 with RadarDataSet

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

the class RadarChartActivitry method setData.

public void setData() {
    float mult = 80;
    float min = 20;
    int cnt = 5;
    ArrayList<RadarEntry> entries1 = new ArrayList<RadarEntry>();
    ArrayList<RadarEntry> entries2 = new ArrayList<RadarEntry>();
    // the chart.
    for (int i = 0; i < cnt; i++) {
        float val1 = (float) (Math.random() * mult) + min;
        entries1.add(new RadarEntry(val1));
        float val2 = (float) (Math.random() * mult) + min;
        entries2.add(new RadarEntry(val2));
    }
    RadarDataSet set1 = new RadarDataSet(entries1, "Last Week");
    set1.setColor(Color.rgb(103, 110, 129));
    set1.setFillColor(Color.rgb(103, 110, 129));
    set1.setDrawFilled(true);
    set1.setFillAlpha(180);
    set1.setLineWidth(2f);
    set1.setDrawHighlightCircleEnabled(true);
    set1.setDrawHighlightIndicators(false);
    RadarDataSet set2 = new RadarDataSet(entries2, "This Week");
    set2.setColor(Color.rgb(121, 162, 175));
    set2.setFillColor(Color.rgb(121, 162, 175));
    set2.setDrawFilled(true);
    set2.setFillAlpha(180);
    set2.setLineWidth(2f);
    set2.setDrawHighlightCircleEnabled(true);
    set2.setDrawHighlightIndicators(false);
    ArrayList<IRadarDataSet> sets = new ArrayList<IRadarDataSet>();
    sets.add(set1);
    sets.add(set2);
    RadarData data = new RadarData(sets);
    data.setValueTypeface(mTfLight);
    data.setValueTextSize(8f);
    data.setDrawValues(false);
    data.setValueTextColor(Color.WHITE);
    mChart.setData(data);
    mChart.invalidate();
}
Also used : RadarEntry(com.github.mikephil.charting.data.RadarEntry) RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) IRadarDataSet(com.github.mikephil.charting.interfaces.datasets.IRadarDataSet) IRadarDataSet(com.github.mikephil.charting.interfaces.datasets.IRadarDataSet) ArrayList(java.util.ArrayList) RadarData(com.github.mikephil.charting.data.RadarData)

Example 2 with RadarDataSet

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

the class RadarChart method drawHighlights.

@Override
protected void drawHighlights() {
    // if there are values to highlight and highlighnting is enabled, do it
    if (mHighlightEnabled && valuesToHighlight()) {
        float sliceangle = getSliceAngle();
        float factor = getFactor();
        PointF c = getCenterOffsets();
        for (int i = 0; i < mIndicesToHightlight.length; i++) {
            RadarDataSet set = mData.getDataSetByIndex(mIndicesToHightlight[i].getDataSetIndex());
            if (set == null)
                continue;
            mHighlightPaint.setColor(set.getHighLightColor());
            // get the index to highlight
            int xIndex = mIndicesToHightlight[i].getXIndex();
            Entry e = set.getEntryForXIndex(xIndex);
            int j = set.getEntryPosition(e);
            float y = e.getVal();
            PointF p = getPosition(c, y * factor, sliceangle * j + mRotationAngle);
            float[] pts = new float[] { p.x, 0, p.x, getHeight(), 0, p.y, getWidth(), p.y };
            mDrawCanvas.drawLines(pts, mHighlightPaint);
        }
    }
}
Also used : RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 3 with RadarDataSet

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

the class RadarChart method drawData.

@Override
protected void drawData() {
    ArrayList<RadarDataSet> dataSets = mData.getDataSets();
    float sliceangle = getSliceAngle();
    // calculate the factor that is needed for transforming the value to
    // pixels
    float factor = getFactor();
    PointF c = getCenterOffsets();
    for (int i = 0; i < mData.getDataSetCount(); i++) {
        RadarDataSet dataSet = dataSets.get(i);
        ArrayList<Entry> entries = dataSet.getYVals();
        Path surface = new Path();
        for (int j = 0; j < entries.size(); j++) {
            mRenderPaint.setColor(dataSet.getColor(j));
            Entry e = entries.get(j);
            PointF p = getPosition(c, e.getVal() * factor, sliceangle * j + mRotationAngle);
            if (j == 0)
                surface.moveTo(p.x, p.y);
            else
                surface.lineTo(p.x, p.y);
        }
        surface.close();
        // draw filled
        if (dataSet.isDrawFilledEnabled()) {
            mRenderPaint.setStyle(Paint.Style.FILL);
            mRenderPaint.setAlpha(dataSet.getFillAlpha());
            mDrawCanvas.drawPath(surface, mRenderPaint);
            mRenderPaint.setAlpha(255);
        }
        mRenderPaint.setStrokeWidth(dataSet.getLineWidth());
        mRenderPaint.setStyle(Paint.Style.STROKE);
        // draw the line (only if filled is disabled or alpha is below 255)
        if (!dataSet.isDrawFilledEnabled() || dataSet.getFillAlpha() < 255)
            mDrawCanvas.drawPath(surface, mRenderPaint);
    }
}
Also used : Path(android.graphics.Path) RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 4 with RadarDataSet

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

the class RadarChart method drawValues.

@Override
protected void drawValues() {
    // if values are drawn
    if (mDrawYValues) {
        float sliceangle = getSliceAngle();
        // calculate the factor that is needed for transforming the value to
        // pixels
        float factor = getFactor();
        PointF c = getCenterOffsets();
        float yoffset = Utils.convertDpToPixel(5f);
        for (int i = 0; i < mData.getDataSetCount(); i++) {
            RadarDataSet dataSet = mData.getDataSetByIndex(i);
            ArrayList<Entry> entries = dataSet.getYVals();
            for (int j = 0; j < entries.size(); j++) {
                Entry e = entries.get(j);
                PointF p = getPosition(c, e.getVal() * factor, sliceangle * j + mRotationAngle);
                if (mDrawUnitInChart)
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(e.getVal()) + mUnit, p.x, p.y - yoffset, mValuePaint);
                else
                    mDrawCanvas.drawText(mValueFormatter.getFormattedValue(e.getVal()), p.x, p.y - yoffset, mValuePaint);
            }
        }
    }
}
Also used : RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) Entry(com.github.mikephil.charting.data.Entry) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Aggregations

RadarDataSet (com.github.mikephil.charting.data.RadarDataSet)4 Paint (android.graphics.Paint)3 PointF (android.graphics.PointF)3 Entry (com.github.mikephil.charting.data.Entry)3 Path (android.graphics.Path)1 RadarData (com.github.mikephil.charting.data.RadarData)1 RadarEntry (com.github.mikephil.charting.data.RadarEntry)1 IRadarDataSet (com.github.mikephil.charting.interfaces.datasets.IRadarDataSet)1 ArrayList (java.util.ArrayList)1