Android MpLine chart y axis on top some is invisible - android

I'm using MpLine chart in my project. My problem is some times top part of y axis is not showing. In my xml I gave fixed height of 75dp to the graph. How can I make the graph to be shown within this height.Any help will appreciated and thanks in advance.

YAxis leftAxis = chart.getAxisLeft();
leftAxis.setAxisMaxValue(1000f); //to set max height place your value in place of 100f
leftAxis.setAxisMinValue(0f); // to set minimum yAxis place
Hope this helps! :)

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);

MPAndroidchart : xaxis labels leaves more empty space at bottom

I want the xaxis labels to come down. Those large labels pushes the graph on top where i am not able to view the graph itself as shown in the figure given below. There is lot of space between the xaxis labels and legends(Legends not shown in figure below). I want to overcome this and view the chart. Find my code below
barChart.getAxisLeft().setAxisMinimum(-1.0f);
barChart.getAxisLeft().setDrawGridLines(false);
barChart.getAxisRight().setDrawGridLines(false);
barChart.getAxisRight().setEnabled(false);
barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
barChart.getXAxis().setDrawGridLines(false);
barChart.getXAxis().setLabelRotationAngle(-90.0f);
barChart.getXAxis().setLabelCount(12);
barChart.getXAxis().setCenterAxisLabels(true);
barChart.getXAxis().setGranularityEnabled(true);
barChart.getXAxis().setValueFormatter(new IndexAxisValueFormatter(xAxisLabelList));
barChart.getXAxis().setAxisMaximum(12f);
barChart.groupBars(1f, 0.5f, 0f);
barChart.invalidate();
You can use barChart.setExtraBottomOffset(-10f); to reduce extra white-space below labels.
And increase your chart height in xml file.

How to hide graph bottom labels in HorizontalBarChart?

I'm trying to hide the bottom labels from the HorizontalBarChart graph (in black border) using MPAndroidChart.
I tried setDrawLabels(false) for XAxis, YAxis left, YAxis right with no success.
What parameter should i change and set to false to hide this line?
It work when i disable the axis right from my horizontal bar chart.
// Right Y Axis
YAxis yr = chart.getAxisRight();
yr.setEnabled(false);
// yr.setDrawGridLines(false);
// yr.setDrawAxisLine(false);
// yr.disableGridDashedLine();
Try:
XAxis xl = chart.getXAxis();
//This will stop the grid lines from being drawn
xl.setDrawGridLines(false);
//This Will stop the labels from being drawn
xl.setDrawLabels(false);

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 set range values from BarChart at 2.0.9v?

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.

Categories

Resources