I am using MPAndroidChart library version 2.2.4. My requirement is I want to set three marker lines in a BarChart with values "Minimum", "Average" and "Maximum" like in the image below, but I can't find any solution for this.
In MPAndroidChart 3.x.x what you are asking for is called a LimitLine
There is an example of how to consume it in the sample project:
LimitLine ll1 = new LimitLine(150f, "Upper Limit");
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setLabelPosition(LimitLabelPosition.RIGHT_TOP);
ll1.setTextSize(10f);
ll1.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
leftAxis.addLimitLine(ll1);
If you require a customized limit line, you will have to look at the instructions in this question here
Related
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);
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:
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.
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.
I have a simple linechart with MPAndroidChart library:
chart.setDrawYValues(false);
chart.setDescription("");
chart.setDrawVerticalGrid(true);
chart.setDrawGridBackground(false);
XLabels xl = holder.chart.getXLabels();
xl.setCenterXLabelText(true);
xl.setPosition(XLabelPosition.BOTTOM);
YLabels yl = holder.chart.getYLabels();
yl.setLabelCount(5);
// set data
chart.setData((LineData) mChartData);
chart.setDrawYValues(true);
chart.setValueTextSize(20f);
// zooming on both axis
chart.setPinchZoom(true);
chart.animateX(1000);
But I have a visualization problem. Labels on the X axis aren't under the relative grid line, but between the two lines (on Y axis I don't have this problem). Is there a way to put Y labels exactly under the relative grid line?
Calling this:
XLabels xl = chart.getXLabels();
xl.setCenterXLabelText(true);
will cause the labels to be drawn between the lines. If you call setCenterXLabelText(false); the labels should be exactly above the individual grid-lines.
Also check the example project LineChart. There the labels are exactly above the lines.
Update
There is no getXLabels method in version 3.1.0. Use this:
chart.xAxis.setCenterAxisLabels(true)