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

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

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

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.

How to solve below chart problems with `MPChartAndroid`?

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

How to make Grid Lines invisible in Android GraphView?

I just want to show only X Y axes and labels on these axes and don't want to show grid lines in Android GraphView. How can I do that?
Thanks in advance.
I believe the following call should do the trick :
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.NONE );
Please do note I haven't tested the above call :)
If you use this all the grid lines will be Removed
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.NONE );
For Setting Horizontal Line visible
your_graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);
For Vertical Line visible
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.VERTICAL);
The following code will remove the grid and then show the X and Y axis
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.NONE);
graph.getViewport().setDrawBorder(true);

Android - How can align the labels' text with their axis?

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.

Categories

Resources