I can't seem to enable padding on the horizontal BarChart in MPAndroidChart... Like on the screenshot below..the word commentary is cut off..even on tablets, both orientations e.t.c
Have a look at the viewport documentation of the MPAndroidChart library.
There you find a method called setExtraOffsets(float left, float top, float right, float bottom) that allows to set additional offsets (as you require) for the chart.
chart.minOffset = 0f
it will remove space on top/right/bottom/left, but it have 1 problem. A half of the HIGHEST label on left/right axis will above (overflow) another view on top)
chart.setViewPortOffsets(left, top, right, bottom)
it help us set the space in top/right/bottom/left but from the axis not from the label (eg: if we set left = 0 we will not see the label on the left). so if I only want to set the space on top only, this function is not suitable
chart.setExtraOffsets(left, top, right, bottom)
chart.extraTopOffset
chart.extraBottomOffset
chart.extraRightOffset
it helps us set space to top/right/bottom/left but it is the EXTRA space so to make it look as same as the design (eg: 40dp), I use
chart.extraTopOffset = getDimension(R.dimen_40dp) - chart.minOffset
Set this function in the getFormattedValue (if you use this) or in any suitable area.
bar.zoomOut()
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
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 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
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.
:) I'm having the following problem: I have a view and i want to add borders to it. What I'm currently trying to do is to set padding to the view (padding from all the sides) and set background color to it which will fill the padding. The thing is that it seems to me that it's possible to set padding either only from top and left or from bottom and right but not from all of them together. I.e if i write
view.setPadding(border,border,border,border)
this will set padding only from top and left. In order to set padding from bottom and right I have to write:
view.setPadding(-border,-border,0,0)
which won't leave left and top padding and so on. If I try to use margin it moves the whole block(the view + the padding area), but not only the view, so this doesn't seem to work either. Any ideas on how to do it without having to use a wrapping layout? Thanks!
What exactly happens when you use the first example?
The four int parameters for setPadding() are for left, top, right, and bottom, respectively. So, calling setPadding(4, 5, 6, 7) should give you 4 pixels of space for the left edge, 5 for the top, 6 for the right, and 7 for the bottom. What result are you getting when you do this? Can you show a screenshot?
What is the content of your view? If it's an image or something similar, perhaps it's not being centered or scaled properly. Try calling setGravity(CENTER);.