Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Stacked Bars Chart

I'm using the MPAndroidChart library, trying to customize the Stacked Bars. The objective is to display the differences between 2 currencies. So suppose this example for January. Currency #1 = 8; Currency #2 = 12

The idea is to show in the same bar both values, but instead of sum the 2 values ( 8 + 12) to have the value 8 "in front" and the value 12 "behind". So the total high of the bar is the max value.

I tried to do that, extending the BarEntry class, and instead of calculate the sum, just set the max value. But I'm seeing only one bar now (the one with value = 12)

Do you know if this kind of logic is supported? Any advice?

like image 377
psabbate Avatar asked Feb 04 '15 15:02

psabbate


People also ask

What does a stacked bar chart show?

Stacked Chart. Bar charts are best used when showing comparisons between categories. Typically, the bars are proportional to the values they represent and can be plotted either horizontally or vertically. One axis of the chart shows the specific categories being compared, and the other axis represents discrete values.


1 Answers

Check out the guide on how to create stacked-bar-charts, as well as the example.

Create an entry in the stacked-bar-chart in the following way:

BarEntry entry = new BarEntry(xValue, new float[] { 8f, 12f });

This will create an entry with a total height of 20, consisting of two different values (8 and 12). The "xValue" is the position this bar will show up on the x-axis.

You can use as many entries for the stack (float array) as you want. If you intend to do only single entries (no stacks), do not use the BarEntry constructor that takes a float array, use the one that only takes a single value.

like image 72
Philipp Jahoda Avatar answered Oct 21 '22 07:10

Philipp Jahoda