How to solve below chart problems with `MPChartAndroid`? - android

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

Related

Android MP Chart library get X-axis height

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

MPAndroidChart, The x-axis line and the grid line overlap?

so how to render only the x axis and not the grid line on top of that. As can be seen in the picture attached the I've set the width of the axis line to be 4 and the gridline width to be 2 .
So the black line shows up on white axis line. I want to just show the axis line. How do I do that.
As it's said in the docs, in order to not draw that gridlines you can try:
chart.getAxisLeft().setDrawGridLines(false)
chart.getAxisRight().setDrawGridLines(false)
Hope it helps :)

How to set padding between value labels and line for MPAndroidChart LineChart

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.

MPAndroidChart: How do I remove gridlines?

In my LineChart beside the lines that are shown on the full numbers parallel to the x-axis, many horizontal gridlines are shown:
How can I get rid of these lines?
Those look like axis lines. You can toggle the axis lines by calling setDrawGridLines(false) on each Chart axis. For example, to clear all of them simply do something like this.
LineChart myChart = ...;
myChart.getXAxis().setDrawGridLines(false);
myChart.getAxisLeft().setDrawGridLines(false);
myChart.getAxisRight().setDrawGridLines(false);

MPAndroidChart Remove space when right axis is disabled

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

Categories

Resources