MPAndroidChart BarChart horizontal / vertical

Kishan Vaghela picture Kishan Vaghela · Mar 4, 2015 · Viewed 19.5k times · Source

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

Answer

Philipp Jahoda picture Philipp Jahoda · Mar 4, 2015

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, check out the documentation on setting data.