Kishan Vaghela Kishan Vaghela - 9 months ago 58
Android Question

MPAndroidChart BarChart horizontal / vertical

I am using the MPAndroidChart library.
In BarChart by-default all the bars are vertical (bottom-up), how to display it in horizontally?

Answer Source

There are two types of bar-charts in terms of orientation.

  • The normal/vertical bar-chart (bars go bottom-up), class BarChart, looks e.g. like this: enter image description here
  • The horizontal bar-chart (bars go left-right), class HorizontalBarChart, looks like this:

    enter image description here

In addition to that, there are also so called stacked-bars (multiple values in a single bar), which can be used in both horizontal- and vertical BarChart. Entries for stacked bars can be created via constructor of the BarEntry class.

// normal entry
BarEntry normalEntry = new BarEntry(float value, int xIndex);

// stacked entry
BarEntry stackedEntry = new BarEntry(float [] values, int xIndex);

Also, make sure you are using the latest-release.