Search in sources :

Example 1 with BarData

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

the class AnotherBarActivity 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 val = (float) (Math.random() * mult) + mult / 3;
        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, "Data Set");
        set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set1.setDrawValues(false);
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        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)

Example 2 with BarData

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

the class BarChartActivityMultiDataset method onProgressChanged.

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    float groupSpace = 0.08f;
    // x4 DataSet
    float barSpace = 0.03f;
    // x4 DataSet
    float barWidth = 0.2f;
    // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"
    int groupCount = mSeekBarX.getProgress() + 1;
    int startYear = 1980;
    int endYear = startYear + groupCount;
    tvX.setText(startYear + "-" + endYear);
    tvY.setText("" + (mSeekBarY.getProgress()));
    ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
    ArrayList<BarEntry> yVals2 = new ArrayList<BarEntry>();
    ArrayList<BarEntry> yVals3 = new ArrayList<BarEntry>();
    ArrayList<BarEntry> yVals4 = new ArrayList<BarEntry>();
    float randomMultiplier = mSeekBarY.getProgress() * 100000f;
    for (int i = startYear; i < endYear; i++) {
        yVals1.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
        yVals2.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
        yVals3.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
        yVals4.add(new BarEntry(i, (float) (Math.random() * randomMultiplier)));
    }
    BarDataSet set1, set2, set3, set4;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set1 = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set2 = (BarDataSet) mChart.getData().getDataSetByIndex(1);
        set3 = (BarDataSet) mChart.getData().getDataSetByIndex(2);
        set4 = (BarDataSet) mChart.getData().getDataSetByIndex(3);
        set1.setValues(yVals1);
        set2.setValues(yVals2);
        set3.setValues(yVals3);
        set4.setValues(yVals4);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        // create 4 DataSets
        set1 = new BarDataSet(yVals1, "Company A");
        set1.setColor(Color.rgb(104, 241, 175));
        set2 = new BarDataSet(yVals2, "Company B");
        set2.setColor(Color.rgb(164, 228, 251));
        set3 = new BarDataSet(yVals3, "Company C");
        set3.setColor(Color.rgb(242, 247, 158));
        set4 = new BarDataSet(yVals4, "Company D");
        set4.setColor(Color.rgb(255, 102, 0));
        BarData data = new BarData(set1, set2, set3, set4);
        data.setValueFormatter(new LargeValueFormatter());
        data.setValueTypeface(mTfLight);
        mChart.setData(data);
    }
    // specify the width each bar should have
    mChart.getBarData().setBarWidth(barWidth);
    // restrict the x-axis range
    mChart.getXAxis().setAxisMinimum(startYear);
    // barData.getGroupWith(...) is a helper that calculates the width each group needs based on the provided parameters
    mChart.getXAxis().setAxisMaximum(startYear + mChart.getBarData().getGroupWidth(groupSpace, barSpace) * groupCount);
    mChart.groupBars(startYear, groupSpace, barSpace);
    mChart.invalidate();
}
Also used : LargeValueFormatter(com.github.mikephil.charting.formatter.LargeValueFormatter) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 3 with BarData

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

the class BarChartActivitySinus method setData.

private void setData(int count) {
    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
    for (int i = 0; i < count; i++) {
        entries.add(mSinusData.get(i));
    }
    BarDataSet set;
    if (mChart.getData() != null && mChart.getData().getDataSetCount() > 0) {
        set = (BarDataSet) mChart.getData().getDataSetByIndex(0);
        set.setValues(entries);
        mChart.getData().notifyDataChanged();
        mChart.notifyDataSetChanged();
    } else {
        set = new BarDataSet(entries, "Sinus Function");
        set.setColor(Color.rgb(240, 120, 124));
    }
    BarData data = new BarData(set);
    data.setValueTextSize(10f);
    data.setValueTypeface(mTfLight);
    data.setDrawValues(false);
    data.setBarWidth(0.8f);
    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) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 4 with BarData

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

the class RealmDatabaseActivityBar 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", "yValue");
    set.setColors(new int[] { ColorTemplate.rgb("#FF5722"), ColorTemplate.rgb("#03A9F4") });
    set.setLabel("Realm BarDataSet");
    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);
    // set data
    mChart.setData(data);
    mChart.setFitBars(true);
    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 5 with BarData

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

the class ListViewBarChartActivity method generateData.

/**
     * generates a random ChartData object with just one DataSet
     * 
     * @return
     */
private BarData generateData(int cnt) {
    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
    }
    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));
    ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
    sets.add(d);
    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
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)

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