Lynerd Lynerd - 1 year ago 714
Android Question

How to create a BarChart with grouped bars with MPAndroidChart?

How can i compare two set of data using

of MPAndroidChart.

It should look like this image below:
enter image description here

I edited a code, I get from a sample project in github.
how can I put together
100f and 110f
value in one
Whole Number

Score score1 = new Score(100f, 0, "Whole Number");
Score score2 = new Score(110f, 0, "Whole Number");

Answer Source

Yes, that can be done quite easily.

What you need is a BarChart with multiple BarDataSets where each set (in your case) represents one sex (men or women).

Example code (without

    List<String> xValues = ...; // "Denmark", "Finland", ...

    XAxis xAxis = chart.getXAxis();
    xAxis.setValueFormatter(new MyValueFormatter(xValues));

    // create 2 datasets 
    BarDataSet set1 = new BarDataSet(valuesMen, "Men");
    BarDataSet set2 = new BarDataSet(valuesWomen, "Women");

    BarData data = new BarData(set1, set2);
    chart.invalidate(); // refresh

If you want to "stack" values in a BarChart above each other, you need to create a stacked-barchart: Android Stacked Bars Chart