android graph-view y axis numbers being cut out
Asked Answered
P

5

7

When trying to create a line graph with the graph-view library in android studio part of the numbers on the vertical line are being cut out.Does anybody know how to fix this?

<com.jjoe64.graphview.GraphView
            android:layout_width="300dp"
            android:layout_height="200dip"
            android:id="@+id/graph"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_gravity="center_horizontal"
            android:nestedScrollingEnabled="false" />

final GraphView graph = (GraphView)findViewById(R.id.graph);
final LineGraphSeries<DataPoint> graphSeries = new LineGraphSeries<DataPoint>(new DataPoint[] { 
    }); // the points are added progressively`
Peloria answered 26/3, 2016 at 2:40 Comment(0)
R
9

I had the same issue. The fix I currently found is to set the padding in the GridLabelRenderer associated with the graph with:

GraphView gv = (GraphView) findViewById(R.id.graph);
GridLabelRenderer glr = gv.getGridLabelRenderer();
glr.setPadding(32); // should allow for 3 digits to fit on screen

As I understand it, the graphview graph expects to have the full screen width by default, so it is cut off by the default padding for the android app (16dp). Setting this padding value in the GridLabelRenderer adds more padding to the graph's edges, decreasing your graph's actual graphing area but allowing more room for the numbers.

For reference, the default padding value associated with the GridLabelRenderer is 20.

I imagine there is a more elegant solution, but this is all I was able to come up with. Hope this helps anybody who comes up with the same issue.

Rags answered 17/4, 2016 at 20:25 Comment(0)
B
2

you can set width of label with following method

mGraph.getGridLabelRenderer().setLabelVerticalWidth(int width)

Maybe you want set value according to the number of digits

Best regards

Bluh answered 28/5, 2017 at 16:14 Comment(0)
A
1

maybe it should be

android:layout_height="200dp"

instead. Best yet, you can specify

graph.getViewport().setMinY(0.0);
graph.getViewport().setMaxY(100.0);

Just my 2 cents :)

Announce answered 26/3, 2016 at 3:59 Comment(0)
P
0

Thanks I also ended up setting the padding larger. It worked for me but there must be away to have it adjust relative to the labels.

Peloria answered 17/4, 2016 at 22:1 Comment(0)
M
0

This is an old question, but for developers with the same problem you can use:

graph.getGridLabelRenderer().setHumanRounding(true);

NOTE: If you are using dates as your x-axis you want to set this to false so that the formatting looks nice. However, if your x-axis is not dates, and you want to round all the axes values then this will work.

Masterwork answered 25/5, 2017 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.