I'm working with MPAndroidChart and I'm really enjoying it since it's really well done.
But I've got a problem that I haven't been able to resolve in a few hours. I've got a seekbar under the three charts (as you can see from the screenshots below) and I'd like to align it with the X-axis, skipping the space occupied by the Y-axis' labels on the left and the padding that gets added on the right.
Have you got any suggestion on how to achieve my goal? Is there a way of knowing the labels' width and the charts' extra-padding? Or, better, can I get the X-axis width?
Thanks in advance! Bye!
Update to the latest version of the library if you have not already.
Then, just remove all offsets from the chart. It's in the documentation.
Call:
chart.setViewPortOffsets(0f, 0f, 0f, 0f);
This will remove all padding / margin / offset from the chart, making the actual content of the chart (the data) being the next thing to your screen edge.
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
When I create a line chart with values for each point, the values on the chart overlap the line, as shown in the screenshot. Is there a function to add padding to the values to raise them up so that this doesn't happen? I've looked all over the place for an answer to this or even someone else having the same issue and haven't found what I'm looking for.
My current chart:
I figured it out.
Based on this line in the source code:
int valOffset = (int) (dataSet.getCircleRadius() * 1.75f);
The padding is calculated based on the radius of the circle on the line, so my solution is to increase the size of the circle, set the outer radius to be transparent, and set the hole color to be the same as the line, which accomplishes what I want. This may not work for everyone, depending on what you're trying to do, but it worked in my case.
I am using MPAndroidChart for drawing a chart in my Android App.
One requirement is I need to bar chart starting from non-zero y position, as suggested in this. So I had using CandleStickChart for the same.
Now my bars are getting cut off at the start and end.
Is there any way to give padding at the start and end of the graph so that it does not get cut off.
Note: My XAxis values are like "4Nov", "5Nov"...
After trying many things, I found out this solution,
graph.getXAxis().setAxisMaximum(candleData.getXMax() + 0.25f);
graph.getXAxis().setAxisMinimum(candleData.getXMin() - 0.25f);
What worked for me is increasing the SpaceTop value.
var yaxis = chart.AxisLeft;
yaxis.SpaceTop = 1.35f;
I use this code to hide right axis:
linechart.getAxisRight().setEnabled(false);
but it has a space like margin of chart (Line chart width is match_parent without margin)
Is there any way to remove this space and make the chart fill to the right edge of screen?
Actually, this space is better for keep. But if you really want to remove, I found this method that can help:
chart.setViewPortOffsets(leftOffset,topOffset,rightOffset,bottomOffset);
You can try this method by custom the view port to remove the blank space.
Firstly you disable the right axis by using
// Java
linechart.getAxisRight().setEnabled(false);
// Kotlin
linechart.axisRight.isEnabled = false
After disabling the right axis there will still be some blank space remaining. All the surrounding padding of the chart can be removed using:
// Java
linechart.setMinOffset(0f);
// Kotlin
linechart.minOffset = 0f
Please also make sure that you don't have any extra offset set by using one of these earlier:
// Kotlin
lineChart.extraLeftOffset
lineChart.extraTopOffset
lineChart.extraRightOffset
lineChart.extraBottomOffset
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.