Search in sources :

Example 11 with BarData

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

the class RealmDatabaseActivityHorizontalBar method setData.

private void setData() {
    RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
    //RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "stackValues", "xIndex"); // normal entries
    // stacked entries
    RealmBarDataSet<RealmDemoData> set = new RealmBarDataSet<RealmDemoData>(result, "xValue", "stackValues", "floatValue");
    set.setColors(new int[] { ColorTemplate.rgb("#8BC34A"), ColorTemplate.rgb("#FFC107"), ColorTemplate.rgb("#9E9E9E") });
    set.setLabel("Mobile OS distribution");
    set.setStackLabels(new String[] { "iOS", "Android", "Other" });
    ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
    // add the dataset
    dataSets.add(set);
    // create a data object with the dataset list
    BarData data = new BarData(dataSets);
    styleData(data);
    data.setValueTextColor(Color.WHITE);
    // set data
    mChart.setData(data);
    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : RealmBarDataSet(com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) ArrayList(java.util.ArrayList) RealmDemoData(com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)

Example 12 with BarData

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

the class RealmWikiExample method setData.

private void setData() {
    // LINE-CHART
    final RealmResults<Score> results = mRealm.where(Score.class).findAll();
    IAxisValueFormatter formatter = new IAxisValueFormatter() {

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return results.get((int) value).getPlayerName();
        }
    };
    lineChart.getXAxis().setValueFormatter(formatter);
    barChart.getXAxis().setValueFormatter(formatter);
    RealmLineDataSet<Score> lineDataSet = new RealmLineDataSet<Score>(results, "scoreNr", "totalScore");
    lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    lineDataSet.setLabel("Result Scores");
    lineDataSet.setDrawCircleHole(false);
    lineDataSet.setColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setCircleColor(ColorTemplate.rgb("#FF5722"));
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setCircleRadius(3.6f);
    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
    dataSets.add(lineDataSet);
    LineData lineData = new LineData(dataSets);
    styleData(lineData);
    // set data
    lineChart.setData(lineData);
    lineChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    // BAR-CHART
    RealmBarDataSet<Score> barDataSet = new RealmBarDataSet<Score>(results, "scoreNr", "totalScore");
    barDataSet.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
    barDataSet.setLabel("Realm BarDataSet");
    ArrayList<IBarDataSet> barDataSets = new ArrayList<IBarDataSet>();
    barDataSets.add(barDataSet);
    BarData barData = new BarData(barDataSets);
    styleData(barData);
    barChart.setData(barData);
    barChart.setFitBars(true);
    barChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
Also used : ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) RealmLineDataSet(com.github.mikephil.charting.data.realm.implementation.RealmLineDataSet) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) RealmBarDataSet(com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet)

Example 13 with BarData

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

the class SimpleFragment method generateBarData.

protected BarData generateBarData(int dataSets, float range, int count) {
    ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
    for (int i = 0; i < dataSets; i++) {
        ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
        for (int j = 0; j < count; j++) {
            entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4));
        }
        BarDataSet ds = new BarDataSet(entries, getLabel(i));
        ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
        sets.add(ds);
    }
    BarData d = new BarData(sets);
    d.setValueTypeface(tf);
    return d;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 14 with BarData

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

the class BarChartRenderer method initBuffers.

@Override
public void initBuffers() {
    BarData barData = mChart.getBarData();
    mBarBuffers = new BarBuffer[barData.getDataSetCount()];
    for (int i = 0; i < mBarBuffers.length; i++) {
        IBarDataSet set = barData.getDataSetByIndex(i);
        mBarBuffers[i] = new BarBuffer(set.getEntryCount() * 4 * (set.isStacked() ? set.getStackSize() : 1), barData.getDataSetCount(), set.isStacked());
    }
}
Also used : BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Paint(android.graphics.Paint) BarBuffer(com.github.mikephil.charting.buffer.BarBuffer)

Example 15 with BarData

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

the class HorizontalBarChartRenderer method drawDataSet.

@Override
protected void drawDataSet(Canvas c, IBarDataSet dataSet, int index) {
    Transformer trans = mChart.getTransformer(dataSet.getAxisDependency());
    mBarBorderPaint.setColor(dataSet.getBarBorderColor());
    mBarBorderPaint.setStrokeWidth(Utils.convertDpToPixel(dataSet.getBarBorderWidth()));
    final boolean drawBorder = dataSet.getBarBorderWidth() > 0.f;
    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();
    // draw the bar shadow before the values
    if (mChart.isDrawBarShadowEnabled()) {
        mShadowPaint.setColor(dataSet.getBarShadowColor());
        BarData barData = mChart.getBarData();
        final float barWidth = barData.getBarWidth();
        final float barWidthHalf = barWidth / 2.0f;
        float x;
        for (int i = 0, count = Math.min((int) (Math.ceil((float) (dataSet.getEntryCount()) * phaseX)), dataSet.getEntryCount()); i < count; i++) {
            BarEntry e = dataSet.getEntryForIndex(i);
            x = e.getX();
            mBarShadowRectBuffer.top = x - barWidthHalf;
            mBarShadowRectBuffer.bottom = x + barWidthHalf;
            trans.rectValueToPixel(mBarShadowRectBuffer);
            if (!mViewPortHandler.isInBoundsTop(mBarShadowRectBuffer.bottom))
                continue;
            if (!mViewPortHandler.isInBoundsBottom(mBarShadowRectBuffer.top))
                break;
            mBarShadowRectBuffer.left = mViewPortHandler.contentLeft();
            mBarShadowRectBuffer.right = mViewPortHandler.contentRight();
            c.drawRect(mBarShadowRectBuffer, mShadowPaint);
        }
    }
    // initialize the buffer
    BarBuffer buffer = mBarBuffers[index];
    buffer.setPhases(phaseX, phaseY);
    buffer.setDataSet(index);
    buffer.setInverted(mChart.isInverted(dataSet.getAxisDependency()));
    buffer.setBarWidth(mChart.getBarData().getBarWidth());
    buffer.feed(dataSet);
    trans.pointValuesToPixel(buffer.buffer);
    final boolean isSingleColor = dataSet.getColors().size() == 1;
    if (isSingleColor) {
        mRenderPaint.setColor(dataSet.getColor());
    }
    for (int j = 0; j < buffer.size(); j += 4) {
        if (!mViewPortHandler.isInBoundsTop(buffer.buffer[j + 3]))
            break;
        if (!mViewPortHandler.isInBoundsBottom(buffer.buffer[j + 1]))
            continue;
        if (!isSingleColor) {
            // Set the color for the currently drawn value. If the index
            // is out of bounds, reuse colors.
            mRenderPaint.setColor(dataSet.getColor(j / 4));
        }
        c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mRenderPaint);
        if (drawBorder) {
            c.drawRect(buffer.buffer[j], buffer.buffer[j + 1], buffer.buffer[j + 2], buffer.buffer[j + 3], mBarBorderPaint);
        }
    }
}
Also used : Transformer(com.github.mikephil.charting.utils.Transformer) BarData(com.github.mikephil.charting.data.BarData) BarEntry(com.github.mikephil.charting.data.BarEntry) BarBuffer(com.github.mikephil.charting.buffer.BarBuffer) HorizontalBarBuffer(com.github.mikephil.charting.buffer.HorizontalBarBuffer)

Aggregations

BarData (com.github.mikephil.charting.data.BarData)32 BarEntry (com.github.mikephil.charting.data.BarEntry)22 ArrayList (java.util.ArrayList)22 BarDataSet (com.github.mikephil.charting.data.BarDataSet)19 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)19 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)4 Paint (android.graphics.Paint)3 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)3 RealmBarDataSet (com.github.mikephil.charting.data.realm.implementation.RealmBarDataSet)3 Transformer (com.github.mikephil.charting.utils.Transformer)3 SuppressLint (android.annotation.SuppressLint)2 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 AxisBase (com.github.mikephil.charting.components.AxisBase)2 LineData (com.github.mikephil.charting.data.LineData)2 MPPointD (com.github.mikephil.charting.utils.MPPointD)2 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)2 PointF (android.graphics.PointF)1 ListView (android.widget.ListView)1 BarChart (com.github.mikephil.charting.charts.BarChart)1 Legend (com.github.mikephil.charting.components.Legend)1