rafaelasguerra
rafaelasguerra

Reputation: 2555

MPAndroidChart / CombinedChart - bar always starts at zero

I am using MPAndroidChart and I have a CombinedChart with several lines and one bar, and even my lines started to draw in negative numbers, the bar always start in zero.

How can I draw the barChart according the begin of the chart?

enter image description here

Upvotes: 2

Views: 931

Answers (1)

Philipp Jahoda
Philipp Jahoda

Reputation: 51431

The bar cannot cover the area below zero because that just would not be correct behaviour of a barchart.

If you add an entry with value 30 on the y-axis, it should cover exactly a range of 30 on the y-axis, and not 30 + whatever space is left to the bottom. That is simply not correct.

In case you still want to have the bars to fill the whole screen, you can "cheat" and use stacked bars with 2 values. The first value represents the "starting point" of the bar, and the second value the actual value.

// e.g. -100 starting point, 30 actual value
// covered area is -100 to 30 on the y-axis
BarEntry stackedEntry = new BarEntry(new float[] {-100, 30}, xIndex);

Upvotes: 3

Related Questions