bar line mpandroid chart - android

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

Related

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

Android MpLine chart y axis on top some is invisible

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! :)

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.

XAxis label angle in MPAndroidChart

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

Categories

Resources