Dika
Dika

Reputation: 2442

I cannot draw negative y-values and positive y-values in one barchart using MPAndroidChart

Please help.. as I wrote in the issue title, I cannot draw negative y-values and positive y-values in one barchart. I use your code and only change a few line of it.

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

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

I only edited line 266-273.

The snippet (original):

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

The snippet (edited):

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

I already open an issue in the author github (issue #183), and I post here in stackoverflow, hoping here I can have faster response.

Thanks, folks

Upvotes: 3

Views: 4098

Answers (2)

Philipp Jahoda
Philipp Jahoda

Reputation: 51421

Update for v3.0.0+:

startAtZero(...) is deprecated, you can make use of:

axis.setAxisMinimum(0f); // start axis zero (min value 0f)
axis.setAxisMaximum(100f); // set axis max value to 100f

To modify or "lock" the range you want your axis to display. Additionally, have a look at the documentation:

Upvotes: 5

manju h
manju h

Reputation: 141

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

Upvotes: 2

Related Questions