Search in sources :

Example 1 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project Gadgetbridge by Freeyourgadget.

the class AbstractChartFragment method createDeepSleepSet.

protected BarDataSet createDeepSleepSet(List<BarEntry> values, String label) {
    BarDataSet set1 = new BarDataSet(values, label);
    //        set1.setDrawCubic(true);
    //        set1.setCubicIntensity(0.2f);
    //        //set1.setDrawFilled(true);
    //        set1.setDrawCircles(false);
    //        set1.setLineWidth(2f);
    //        set1.setCircleSize(5f);
    //        set1.setFillColor(ColorTemplate.getHoloBlue());
    set1.setDrawValues(false);
    //        set1.setHighLightColor(Color.rgb(244, 117, 117));
    //        set1.setColor(Color.rgb(76, 90, 255));
    set1.setValueTextColor(CHART_TEXT_COLOR);
    return set1;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet)

Example 2 with BarDataSet

use of com.github.mikephil.charting.data.BarDataSet in project android-client by GenesisVision.

the class ProfitChartView method createBarDataSet.

private BarDataSet createBarDataSet(List<BarEntry> data) {
    BarDataSet dataSet = new BarDataSet(data, "");
    dataSet.setLabel("");
    dataSet.setDrawValues(false);
    dataSet.setColor(ContextCompat.getColor(getContext(), lineColor));
    dataSet.setColors(ContextCompat.getColor(getContext(), R.color.colorPrimary), ContextCompat.getColor(getContext(), R.color.transactionRed), ContextCompat.getColor(getContext(), R.color.transactionGreen));
    return dataSet;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet)

Example 3 with BarDataSet

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

the class ListViewMultiChartActivity method generateDataBar.

/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Bar data
 */
private BarData generateDataBar(int cnt) {
    ArrayList<BarEntry> entries = new ArrayList<>();
    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
    }
    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setHighLightAlpha(255);
    BarData cd = new BarData(d);
    cd.setBarWidth(0.9f);
    return cd;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) BarData(com.github.mikephil.charting.data.BarData) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Example 4 with BarDataSet

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

the class SimpleFragment method generateBarData.

protected BarData generateBarData(int dataSets, float range, int count) {
    ArrayList<IBarDataSet> sets = new ArrayList<>();
    for (int i = 0; i < dataSets; i++) {
        ArrayList<BarEntry> entries = new ArrayList<>();
        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 5 with BarDataSet

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

the class StackedBarActivityNegative method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);
    setTitle("StackedBarActivityNegative");
    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.setDrawGridBackground(false);
    chart.getDescription().setEnabled(false);
    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);
    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);
    chart.setHighlightFullBarEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getAxisRight().setAxisMaximum(25f);
    chart.getAxisRight().setAxisMinimum(-25f);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawZeroLine(true);
    chart.getAxisRight().setLabelCount(7, false);
    chart.getAxisRight().setValueFormatter(new CustomFormatter());
    chart.getAxisRight().setTextSize(9f);
    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private final DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });
    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);
    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> values = new ArrayList<>();
    values.add(new BarEntry(5, new float[] { -10, 10 }));
    values.add(new BarEntry(15, new float[] { -12, 13 }));
    values.add(new BarEntry(25, new float[] { -15, 15 }));
    values.add(new BarEntry(35, new float[] { -17, 17 }));
    values.add(new BarEntry(45, new float[] { -19, 20 }));
    values.add(new BarEntry(45, new float[] { -19, 20 }, getResources().getDrawable(R.drawable.star)));
    values.add(new BarEntry(55, new float[] { -19, 19 }));
    values.add(new BarEntry(65, new float[] { -16, 16 }));
    values.add(new BarEntry(75, new float[] { -13, 14 }));
    values.add(new BarEntry(85, new float[] { -10, 11 }));
    values.add(new BarEntry(95, new float[] { -5, 6 }));
    values.add(new BarEntry(105, new float[] { -1, 2 }));
    BarDataSet set = new BarDataSet(values, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(Color.rgb(67, 67, 72), Color.rgb(124, 181, 236));
    set.setStackLabels(new String[] { "Men", "Women" });
    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    chart.setData(data);
    chart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) BarEntry(com.github.mikephil.charting.data.BarEntry) XAxis(com.github.mikephil.charting.components.XAxis) BarData(com.github.mikephil.charting.data.BarData)

Aggregations

BarDataSet (com.github.mikephil.charting.data.BarDataSet)41 ArrayList (java.util.ArrayList)27 BarEntry (com.github.mikephil.charting.data.BarEntry)25 BarData (com.github.mikephil.charting.data.BarData)24 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)22 Intent (android.content.Intent)8 Paint (android.graphics.Paint)5 List (java.util.List)4 SuppressLint (android.annotation.SuppressLint)2 XAxis (com.github.mikephil.charting.components.XAxis)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 IDataSet (com.github.mikephil.charting.interfaces.datasets.IDataSet)2 Context (android.content.Context)1 Path (android.graphics.Path)1 PointF (android.graphics.PointF)1 RectF (android.graphics.RectF)1 BarChart (com.github.mikephil.charting.charts.BarChart)1 AxisBase (com.github.mikephil.charting.components.AxisBase)1 Legend (com.github.mikephil.charting.components.Legend)1 LimitLine (com.github.mikephil.charting.components.LimitLine)1