Search in sources :

Example 1 with BarEntry

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

the class ProfitChartView method setChart.

public void setChart(List<Chart> charts) {
    if (charts.isEmpty()) {
        chart.clear();
        return;
    }
    List<Entry> lineEntries = new ArrayList<>();
    // List<BarEntry> barEntries = new ArrayList<>();
    float index = 0;
    for (Chart chart : charts) {
        lineEntries.add(new Entry(index, chart.getTotalProfit().floatValue()));
        // barEntries.add(new BarEntry(index, new float[]{
        // chart.getManagerFund().floatValue() + chart.getInvestorFund().floatValue(),
        // chart.getLoss().floatValue(),
        // chart.getProfit().floatValue()}));
        index++;
    }
    CombinedData data = new CombinedData();
    data.setData(getLineData(lineEntries));
    // data.setData(getBarData(barEntries));
    chart.setData(data);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) ArrayList(java.util.ArrayList) CombinedData(com.github.mikephil.charting.data.CombinedData) Chart(io.swagger.client.model.Chart) CombinedChart(com.github.mikephil.charting.charts.CombinedChart)

Example 2 with BarEntry

use of com.github.mikephil.charting.data.BarEntry 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 3 with BarEntry

use of com.github.mikephil.charting.data.BarEntry 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 4 with BarEntry

use of com.github.mikephil.charting.data.BarEntry 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)

Example 5 with BarEntry

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

the class HorizontalBarBuffer method feed.

@Override
public void feed(IBarDataSet data) {
    float size = data.getEntryCount() * phaseX;
    float barWidthHalf = mBarWidth / 2f;
    for (int i = 0; i < size; i++) {
        BarEntry e = data.getEntryForIndex(i);
        if (e == null)
            continue;
        float x = e.getX();
        float y = e.getY();
        float[] vals = e.getYVals();
        if (!mContainsStacks || vals == null) {
            float bottom = x - barWidthHalf;
            float top = x + barWidthHalf;
            float left, right;
            if (mInverted) {
                left = y >= 0 ? y : 0;
                right = y <= 0 ? y : 0;
            } else {
                right = y >= 0 ? y : 0;
                left = y <= 0 ? y : 0;
            }
            // multiply the height of the rect with the phase
            if (right > 0)
                right *= phaseY;
            else
                left *= phaseY;
            addBar(left, top, right, bottom);
        } else {
            float posY = 0f;
            float negY = -e.getNegativeSum();
            float yStart = 0f;
            // fill the stack
            for (int k = 0; k < vals.length; k++) {
                float value = vals[k];
                if (value >= 0f) {
                    y = posY;
                    yStart = posY + value;
                    posY = yStart;
                } else {
                    y = negY;
                    yStart = negY + Math.abs(value);
                    negY += Math.abs(value);
                }
                float bottom = x - barWidthHalf;
                float top = x + barWidthHalf;
                float left, right;
                if (mInverted) {
                    left = y >= yStart ? y : yStart;
                    right = y <= yStart ? y : yStart;
                } else {
                    right = y >= yStart ? y : yStart;
                    left = y <= yStart ? y : yStart;
                }
                // multiply the height of the rect with the phase
                right *= phaseY;
                left *= phaseY;
                addBar(left, top, right, bottom);
            }
        }
    }
    reset();
}
Also used : BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

BarEntry (com.github.mikephil.charting.data.BarEntry)42 ArrayList (java.util.ArrayList)28 BarData (com.github.mikephil.charting.data.BarData)26 BarDataSet (com.github.mikephil.charting.data.BarDataSet)24 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)15 Transformer (com.github.mikephil.charting.utils.Transformer)6 Paint (android.graphics.Paint)5 BarBuffer (com.github.mikephil.charting.buffer.BarBuffer)5 Entry (com.github.mikephil.charting.data.Entry)5 BufferedReader (java.io.BufferedReader)5 IOException (java.io.IOException)5 Drawable (android.graphics.drawable.Drawable)3 IValueFormatter (com.github.mikephil.charting.formatter.IValueFormatter)3 MPPointF (com.github.mikephil.charting.utils.MPPointF)3 InputStreamReader (java.io.InputStreamReader)3 SuppressLint (android.annotation.SuppressLint)2 HorizontalBarBuffer (com.github.mikephil.charting.buffer.HorizontalBarBuffer)2 XAxis (com.github.mikephil.charting.components.XAxis)2 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)2 File (java.io.File)2