Search in sources :

Example 16 with IBarDataSet

use of com.github.mikephil.charting.interfaces.datasets.IBarDataSet in project MPAndroidChart by PhilJay.

the class BarChartActivity method setData.

private void setData(int count, float range) {
    float start = 1f;
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = (int) start; i < start + count + 1; i++) {
        float mult = (range + 1);
        float val = (float) (Math.random() * mult);
        if (Math.random() * 100 < 25) {
            yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
        } else {
            yVals1.add(new BarEntry(i, val));
        }
    }
    BarDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals1);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(yVals1, "The year 2017");
        set1.setDrawIcons(false);
        set1.setColors(ColorTemplate.MATERIAL_COLORS);
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTfLight);
        data.setBarWidth(0.9f);
        mChart.setData(data);
    }
}
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) SuppressLint(android.annotation.SuppressLint)

Example 17 with IBarDataSet

use of com.github.mikephil.charting.interfaces.datasets.IBarDataSet in project MPAndroidChart by PhilJay.

the class HorizontalBarChartActivity method setData.

private void setData(int count, float range) {
    float barWidth = 9f;
    float spaceForBar = 10f;
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = 0; i < count; i++) {
        float val = (float) (Math.random() * range);
        yVals1.add(new BarEntry(i * spaceForBar, val, getResources().getDrawable(R.drawable.star)));
    }
    BarDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals1);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(yVals1, "DataSet 1");
        set1.setDrawIcons(false);
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTfLight);
        data.setBarWidth(barWidth);
        mChart.setData(data);
    }
}
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) SuppressLint(android.annotation.SuppressLint)

Example 18 with IBarDataSet

use of com.github.mikephil.charting.interfaces.datasets.IBarDataSet in project MPAndroidChart by PhilJay.

the class StackedBarActivity method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    tvX.setText("" + (mSeekBarX.getProgress() + 1));
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
        float mult = (mSeekBarY.getProgress() + 1);
        float val1 = (float) (Math.random() * mult) + mult / 3;
        float val2 = (float) (Math.random() * mult) + mult / 3;
        float val3 = (float) (Math.random() * mult) + mult / 3;
        yVals1.add(new BarEntry(i, new float[] { val1, val2, val3 }, getResources().getDrawable(R.drawable.star)));
    }
    BarDataSet set1;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set1.setValues(yVals1);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set1 = new BarDataSet(yVals1, "Statistics Vienna 2014");
        set1.setDrawIcons(false);
        set1.setColors(getColors());
        set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        data.setValueFormatter(new MyValueFormatter());
        data.setValueTextColor(Color.WHITE);
        mChart.setData(data);
    }
    mChart.setFitBars(true);
    mChart.invalidate();
}
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) MyValueFormatter(com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter)

Example 19 with IBarDataSet

use of com.github.mikephil.charting.interfaces.datasets.IBarDataSet in project MPAndroidChart by PhilJay.

the class BarChartRenderer method drawHighlighted.

@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    BarData barData = mChart.getBarData();
    for (Highlight high : indices) {
        IBarDataSet set = barData.getDataSetByIndex(high.getDataSetIndex());
        if (set == null || !set.isHighlightEnabled())
            continue;
        BarEntry e = set.getEntryForXValue(high.getX(), high.getY());
        if (!isInBoundsX(e, set))
            continue;
        Transformer trans = mChart.getTransformer(set.getAxisDependency());
        mHighlightPaint.setColor(set.getHighLightColor());
        mHighlightPaint.setAlpha(set.getHighLightAlpha());
        boolean isStack = (high.getStackIndex() >= 0 && e.isStacked()) ? true : false;
        final float y1;
        final float y2;
        if (isStack) {
            if (mChart.isHighlightFullBarEnabled()) {
                y1 = e.getPositiveSum();
                y2 = -e.getNegativeSum();
            } else {
                Range range = e.getRanges()[high.getStackIndex()];
                y1 = range.from;
                y2 = range.to;
            }
        } else {
            y1 = e.getY();
            y2 = 0.f;
        }
        prepareBarHighlight(e.getX(), y1, y2, barData.getBarWidth() / 2f, trans);
        setHighlightDrawPos(high, mBarRect);
        c.drawRect(mBarRect, mHighlightPaint);
    }
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) Transformer(com.github.mikephil.charting.utils.Transformer) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) Range(com.github.mikephil.charting.highlight.Range) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 20 with IBarDataSet

use of com.github.mikephil.charting.interfaces.datasets.IBarDataSet in project MPAndroidChart by PhilJay.

the class HorizontalBarChartRenderer method initBuffers.

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

Aggregations

IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)22 BarData (com.github.mikephil.charting.data.BarData)16 BarEntry (com.github.mikephil.charting.data.BarEntry)11 ArrayList (java.util.ArrayList)11 BarDataSet (com.github.mikephil.charting.data.BarDataSet)8 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 RectF (android.graphics.RectF)2 Drawable (android.graphics.drawable.Drawable)2 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 LineData (com.github.mikephil.charting.data.LineData)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 MPPointD (com.github.mikephil.charting.utils.MPPointD)2 MPPointF (com.github.mikephil.charting.utils.MPPointF)2 RealmDemoData (com.xxmassdeveloper.mpchartexample.custom.RealmDemoData)2 Typeface (android.graphics.Typeface)1 BarChart (com.github.mikephil.charting.charts.BarChart)1