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

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.

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 - Horizontal bar chart - Justify label text to the left

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.

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

How to set absolute (not %) position for the center of a shape drawable gradient?

I've got a shape drawable with a radial gradient inside it. The shape is a rectangle, and I'm trying to position the center of the radial gradient near the bottom right corner. I can get it in the general vicinity using the centerX and centerY attributes set to values like 0.98, but I'm dealing with rectangles of different heights (same width), so the taller the rectangle is, the higher the center position is, relative to the bottom right corner.
It seems I can only position the center as a percentage of the view width/height, contrary to the documentation. That is, even without the "%" in the value, it is treated as a percentage.
What I'd like to do is somehow say "put the center 5dp up and to the left of the bottom right corner". Any ideas on how to accomplish that?
You might try use a Layer-List, there you can specify margins of overlaying layer items, which can be drawables.

How to add custom view at particular point in relative layout in android?

Hi am developing android application with graph view. i got an open source graph application to show my values with graph lines. Here i am face problem while adding view. i am not able to add my custom view properly with relative layout.
Here i attached my custom view alignment .
In that image point 1. is my result while trying to add mt custom view.
But i need to add that as shown in 2. part.
my custom view is like shown in 3 .part
I am getting that line starting x,y and ending x,y values. I tried with that values but i got result as 2 part. Please provide me any suggestion
Or let me know is there any alignments required.
My code is like
View View v1=infalter.inflate(R.layout.bullet, null);
RelativeLayout.LayoutParams rl=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rl.setMargins(myX,myY, 0, 0);
mRelative.addView(v1,rl);
You are setting the margins for the x, y point that you got, so the view will start at x, y at the top left, which is what you got. You want to align the bottom center of the view, so you need to calculate this.
So:
top= y - viewHeight
left= x - viewWidht/2
I don't know what your values of myX and myY are, but it looks like you're trying to align the top right with your x and y margins applied to the right and top respectively. If this is indeed the case, you're probably better off with something like this:
rl.setMargins(0, 0, myX, myY);
rl.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
The arguments to setMargins go in order as follows: left, top, right, bottom. If your myX value is the right margin and you want the object right aligned, the code above will specify these two preferences.
While playing with a relative layout to provide a help screen overlay I ran into weird things and had to set margins relative to the bottom right and not upper left. So I had a rule to align the view at the bottom and the right + the margins.
Maybe that will help.

Categories

Resources