MPAndroidChart - How to set range values from BarChart at 2.0.9v? - android

I´m using MPAndroidChart 2.0.9 version. I would like to set labels on y-axis from 0 to 100 and display always this range, but i can´t find the chart.setYRange() method.

The range can be customized via the YAxis class.
Here is the documentation: https://github.com/PhilJay/MPAndroidChart/wiki/YAxis-%28YLabels%29
YAxis y = chart.getAxisLeft();
y.setAxisMaxValue(100);
y.setAxisMinValue(0);

You can try to write this:
yAxis.setLabelCount(x)
This code should give you labels in steps of x, assuming you set a min and max value.
Example of my code:
YAxis y = mChart.getAxisLeft();
y.setAxisMaxValue(100);
y.setAxisMinValue(0);
y.setLabelCount(6);
This will give me labels from 0 to 100 in 6 steps, so: 0-20-40-60-80-100.

Related

I am using mp chart library for android and want that my maximum draw value to be on top of line and min draw value to be above the line

It wiil be great also to put margin there.
I am attaching also 2 sc .
Find the minValue and maxValue then the set the axisMin and axisMax values.
//use getAxisRight for right Y axis
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setAxisMinimum(minValue);
//above line would be the same except
//"1" should be calculated and not hard coded
leftAxis.setAxisMaximum(maxValue - 1);

How to draw Range Chart MpAndroidChart with negative and positive value?

I'm using MPAndroidChart to draw Chart in my App. I have a problem when my Chart display data with value from negavite to positive.I reseached example of this lib by using BarChart but have not solution.
E.g. Column 1 will draw from -10 to 30. (has minValue and maxValue)
I don't know how to do that, BarChart is always draw from zero line.
I am setting like below:
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setAxisMaximum(100);
leftAxis.setAxisMinimum(-100);
float[] data = new float[]{-10f, 30f};
values.add(new BarEntry(1, data));
But have not effect. Please help me.
I want to draw chart like this image bellow:

Display y axis value with B(billion) or M(million) in MPAndroidChart

I have some values on Y-axis(look at picture)! I want to them be like 100M, 200M,...
I'm using MPAndroidchart. Is there any solution?
You can achieve this with an AxisValueFormatter . You can write your own pretty easily if you need to, but MPAndroidChart already comes with a LargeValueFormatter that does what you are describing.
From the AxisValueFormatter help page section on predefined formatters:
LargeValueFormatter: Can be used for formatting large values >
"1,000". It will turn values like "1,000" into "1k", "1,000,000" will
be "1m" (million), "1,000,000,000" will be "1b" (billion) and values
like one trillion will be e.g. "1t".
Example use:
YAxis left = chart.getAxisLeft();
left.setValueFormatter(new LargeValueFormatter());

MPAndroidChart Programmatically Change YAxis Range

Is there a way to programmatically change the YAxis Range of a chart in MPAndroidChart?
For instance, given the YAxis displays 0,10, I want to programmatically set the YAxis to -5,+5, but I want to do this several times during the course of an application.
From the documentation, I think you should give a try with a combination of :
setVisibleYRangeMaximum(float maxYRange, AxisDependency axis): Sets the size of the area (range on the y-axis) that should be maximum visible at once. You also need to provide the axis this constraint should apply to.
moveViewToY(float yValue, AxisDependency axis): Centers the viewport to the specified y-value on the provided y-axis (left or right).
Code for your example:
yourChart.setVisibleYRangeMaximum(10, YAxis.AxisDependency.LEFT);
yourChart.moveViewToY(0, YAxis.AxisDependency.LEFT);
yourChart.invalidate();

MPAndroidChart - How to make sure that max Y Label shows up

I'm trying to make a line chart using MPAndroidChart that has a Y Axis with a min value of 0 and a max of 255, but I haven't been able to get the max value to show up when viewing the chart. It always shows the top value as something like 240 or 250. I've tried a couple variations of setting the label count but that hasn't helped either. Here is what I'm doing right now.
YAxis yAxis = lineChart.getAxisLeft();
yAxis.setAxisMaxValue(255);
yAxis.setAxisMinValue(0);
yAxis.setLabelCount(5);
I'm setting these before I add the data to the chart.

Categories

Resources