I m using MPANdroidChartLibrary, but facing issues when showing vertical legends in the bottom of the chart. The last legend cut off.
See attached image:
As the last legend is cut after AM registration in small devices.
I follow Answer1
3: MpAndroidChart Piechart legends cutting issue at the bottom center and Answer2 posts on stack overflow but nothing works for me.
Surprisingly, This issue only comes on smaller devices even after using scroll view around the chart while on large device like above 6 inch all legends are visible properly.
Add as much offset as you legend grows.
there are two methods add the specified padding at the top and bottom of the chart
mPiecPieChart.setExtraBottomOffset(12f);//from bottom side if legends are bottom side
mPiecPieChart.setExtraTopOffset(12f);//if legends are on top side or change both if legend are on both sides
by this line of code you can set margin between below line and legend last entry!
legend.setYOffset(50f);
as your legends increase you can increase value and on reducing legend entries you can reduce this value also!
Legend legend = chart.getLegend();
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
legend.setOrientation(Legend.LegendOrientation.VERTICAL);
legend.setDrawInside(false);
legend.setYOffset(50f);//here value changes
Related
Let's say I have an Activity containing a ChartView (blue rectangle)
Now, I want to place another View on top of it that will stretch from the X-axis all the way to the top of ChartView.
I tried to do that by setting the margin-bottom equal to the height of the X-axis (red area), but I don't know how to get its height
How can I achieve this effect? Is there a way to get X-axis height in Android MP Chart? Or maybe there is a walkaround that will have a similar result?
Desirable outcome (the gray area is a view placed on top of the chart):
chart.getXAxis().mLabelHeight returns the height of x-Axis by pixel.
You can get it after OnGlobalLayoutListener, because it is calculated after x-Axis is drawn.
----------Updated Jun 22nd
another way is to use "getHeight() - mViewPortHandler.contentBottom()", but mViewPortHandler is protected, so an extended chart is necessary to provide access to mViewPortHandler
I have 3 issue related to MPChartAndroid.
How to make chart to see selected values.
1. Add space to the left of LeftAxis and to the right of rightAxis to fully see the values.
2. how to make first and last chart value to fully see the values.
3. Add space under xAxis to see the cut text.
To overcome issue with cutoff x-Axis label, you need to set some extra space on bottom of your chart view.
mLineChart.setExtraOffsets(left,top,right,bottom); try code below
mLineChart.setExtraOffsets(0,0,0,10);
For overcome issue with overlapping value on axis line you need to set some spacing (start position of lines) on x-Axis, try code below
xAxis.setSpaceMax(0.01f);
xAxis.setSpaceMin(0.01f);
also try xAxis.setAvoidFirstLastClipping(true);
I want to combine 3 bar series and 3 line series in one chart using achartengine.
When I specify the type of chart as BarChart and give it 3 series, things work right. The bars widths are what I set and the spacing and colouring is correct:
(see image here: http://i42.tinypic.com/ifu1ap.jpg)
But when I specify the chart type as
mChart = ChartFactory.getCombinedXYChartView(getView().getContext(), mDataset, mRenderer, new String[] {BarChart.TYPE, BarChart.TYPE, BarChart.TYPE, LineChart.TYPE, LineChart.TYPE,LineChart.TYPE });
the bars display on top of each other and the widths aren't right:
(see image here: http://i43.tinypic.com/2vum2xv.jpg)
Neither XYMultipleSeriesRenderer.setBarWidth() nor XYSeriesRenderer.setLineWidth() works for the bar widths.
I thought that if I added the XYSeries x values with an offset that I could fix the overlapping bars issue but then the widths of the bars are still not what I set it to be.
Does anyone know (the right way) how to make a chart that shows multiple bar and line series in one chart?
You are correct about using an offset to render the bars such as they don't overlap.
However, for spacing them, you need to use renderer.setBarSpacing(2); which means that the space between 2 items in the same series is equal to two times width of one bar.
I have an application using Achartengine and I am trying to move the legend independently. Every time I try to move it, it has some side effect.
Here is an image of the application:
[Image of my application where the legend overlaps the x axis labels but still shows]
[IMG]http://i42.tinypic.com/2jd2y6g.png[/IMG]
http://i42.tinypic.com/2jd2y6g.png
Here is an image of the application when I apply some solutions that I found here on stackoverflow:
[Image of my application where the legend has disappeared under the bottom of the screen]
[IMG]http://i44.tinypic.com/16bipmp.png[/IMG]
http://i44.tinypic.com/16bipmp.png
The thing I tried is to set the legend height with this method mRenderer.setLegendHeight(20);
The only thing I want to do is to move the legend down a few pixels so that it will not overlap the x axis labels or the x axis label name.
Moving the legend all the way to the top would be even better.
BTW I am also using mRenderer.setMargins(new int[] { 20, 30,0, 20 }); to set the margins and I have tried different combinations.
Any suggestions?
I can't post images yet.
You need to set a higher bottom margin, the third value in the array:
renderer.setMargins(new int[] { top, left, bottom, right });
You can also try the legend fit:
renderer.setFitLegend(true);
I'm using achartengine. I don't know how to align the labels' text with their axis. On some screens, the text is centered with the axis; on other screens, they're on the bottom or on the top of the axis.
Is there a way to globally put them in the center of the axis?
I think you can use the following:
mRenderer.setYLabelsAlign(Align.LEFT, 0)
If you want to set the alignment on the right side of the grid, just set Align.LEFT, which means they are align on the left.
Reading these two threads might clear it more: Android AChartEngine - Unable to change textColor of Y-Axis Labels and AChartEngine : Align Y-Axis Labels on right side of Axis itself
Hope it helps.