I am unable to draw negative y values ​​and positive y values ​​in the same barcher using MPAndroidChart

Please help .. as I wrote in the title of the question, I cannot draw negative y values ​​and positive y values ​​in the same velvet. I am using your code and only changing a few lines.

original source: https://raw.githubusercontent.com/PhilJay/MPAndroidChart/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java .

edited source: https://db.tt/FWGvAZOZ

I only edited line 266-273.

Excerpt (original):

for (int i = 0; i < count; i++) {
    float mult = (range + 1);
    float val = (float) (Math.random() * mult);
    yVals1.add(new BarEntry(val, i));
}

      

Edited snippet:

for (int i = 0; i < count; i++) {
    float val = (float) ((double)1.0 * (float)i) -5;
    yVals1.add(new BarEntry(val, i));           
}

      

I am already opening an issue in the author of github (issue # 183) and I am posting it here on stackoverflow hoping I have a faster answer here.

Thanks guys

+3


source to share


2 answers


Use setStartAtZero(false)

on BarChart

to draw negative values.

Update:



Since version 2.0.7 the libraries startAtZero(...)

no longer need to be installed for the diagram, but for YAxis

.

+4


source


 // For setting negative axis for y
 BarChart chart = (BarChart) findViewById(R.id.chart);
 chart.getAxisLeft().setStartAtZero(false);
 chart.getAxisRight().setStartAtZero(false);

      



+1


source







All Articles