MPAndroidChart - Horizontal bar chart - Justify label text to the left - android

I'm using MPAndroidChart to create a horizontal bar graph.
Is it possible to justify the label text from the left as opposed to the right?
Code:
mChart.getXAxis().setValueFormatter(new LabelValueFormatter(set1));
mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
mChart.getXAxis().setXOffset(100);

Setting the axis position to the TOP and reversing the offset worked:
mChart.getXAxis().setValueFormatter(new LabelValueFormatter(set1));
mChart.getXAxis().setPosition(XAxis.XAxisPosition.TOP);
mChart.getXAxis().setXOffset(-350);

you can set to draw the values above the bars by:
mChart.setDrawValueAboveBar(true);
the result is like this image.

Related

How to center domain label below bar in a bar chart?

Currently, each bar's domain label appears below the left hand side of each bar, as pictured here:
Is there a way to position labels below each bar's center ?
This should do the trick:
XYGraphWidget.LineLabelStyle style = plot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM);
style.getPaint().setTextAlign(Paint.Align.CENTER);
I believe you are doing that on canvas.
You already know the width of the bar.
Measure the text size (width) to be displayed using
Measuring text height to be drawn on Canvas ( Android )
(barWidth/2 - textWidth/2) + barLeft should do, i think.

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

MpAndroid chart Android - How to remove horizontal highlight Indicator

I am using MpAndroid for chart in Android.
When I touch any point in chart two line are drawn on chart(Vertical and Horizontal highlight Indicators).
1 line parallel to X axis(Horizontal Indicator) and another parallel to Y Axis(Vertical Indicator).
I want to show only Vertical Indicator.
How can I do it.
there is a method for a DataSet (e.g. CandleDataSet)
candleDataSet.setDrawHorizontalHighlightIndicator(false);

achartengine; fitting all x axis labels without clipping, and without margins on graph

I'm using a fill to color the area below my chart, and I want the graph to take up the entire view, so I'm setting zero margin on the right and left in my renderer.
mRenderer.setMargins(new int[]{20, 0, 20, 0});
Graph renders great; uses all horizontal space and doesn't look wonky like it does without fill extending to right or left margins when they're set to > 0 values.
I'm also using custom text labels, aligned center, and I'm getting the outer two labels clipped; setting padding on x labels amplifies the problem by pushing labels off view.
Is there a way I can fit all the x labels in without the truncation, and without having to use margins? I can fit them all using margins, but then it just looks funky using the fill below.
Ideally, I guess there'd be some way to set alignment on each text label individually; probably asking for a lot. Or, a means to specify whether it should fit x labels when using custom text labels, such that it would align right on the first, and align left on the last.
Thanks

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