XAxis label angle in MPAndroidChart - android

I am using MPAndroidChart library for my project.
Is it possible to rotate the labels of the XAxis by 270 degrees so that I can fit more text?

Original answer:
Unfortunately it is currently not possible to rotate the values on the x-axis of a chart to a certain degree / angle.
You will have to implement such a feature yourself.
UPDATE:
As of v2.1.5 this feature is now available:
XAxis xAxis = chart.getXAxis();
xAxis.setLabelRotationAngle(...);

do it simply by
XAxis xAxis=barChart.getXAxis();
xAxis.setLabelRotationAngle(-45);

Related

bar line mpandroid chart

I have a chart and use mpandroidchart
the shape is as shown below
how can my line be neat and not too sideways?
If you are using version above 3 then you need to modify your xAxis as follows and last two lines of code will solve your issue:
// xAxis customization
XAxis xAxis = combinedChart.getXAxis();
// Following code have no effect but you can change it if required
xAxis.setGranularity(1f);
xAxis.setGranularityEnabled(true);
xAxis.setCenterAxisLabels(false);
xAxis.setDrawGridLines(false);
//xAxis.setXOffset(2);
// Setting maximum limit of xAxis
xAxis.setAxisMaximum(barData().getEntryCount());
// Setting position of xAxis
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
// This is used to fix bar width of first bar
**xAxis.setSpaceMin(barData().getBarWidth() / 2f);
xAxis.setSpaceMax(barData().getBarWidth() / 2f);**
I'm not sure but its worked for me.
This error comes from X Axis starting point.
Set starting point as 1.
xAxis.setAxisMinimum(1); // or xAxis.setAxisMinimum(2);

How to make a mpandroidchart horizontol-chart draw from right to left

I use MPAndroidChart in my project, today I meet a problem,please look the screenshot.
enter image description here
I know how to implement the left diagram,but I don't know the right how to implement.
I know the answer:
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.TOP);
YAxis leftYAxis = barChart.getAxisLeft();
leftYAxis.setInverted(true);

Values under xAxis doesn't display in LineChart MPAdroidChart

I have created such chart, but problem is that values under xAxis doesn't displays fully, so there should be "2017-08-10", instead I see "20", If I zoom that chart, I can see all data under the xAxis. How to see all values?
I have also tried to change RotationAngle to 25 and 90, but still no results.
XAxis xAxis = chart.getXAxis();
xAxis.setValueFormatter(new MyXAxisValueFormatter(datesArray));
xAxis.setLabelRotationAngle(45);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getDescription().setEnabled(false);
I have also removed xAxis.setLabelRotationAngle(45);But, in that case dates overlap each other.
Set bottom padding to chart using setExtraOffsets like.
setExtraOffsets(float left, float top, float right, float bottom)

XAxis label angle in MPAndroidChart causes chart to move up

When i use xAxis.setLabelRotationAngle(-45); to rotate the labels of the xAxis on a bar chart,it causes the chart to jump up on the charts.BarChart control.
Chart without label rotation
Chart with label rotation
How do i prevent this from happening while keeping the rotation?

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