Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android graph-view y axis numbers being cut out

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`
like image 649
Noah bouma Avatar asked Mar 26 '16 02:03

Noah bouma


3 Answers

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.

like image 147
HunterCM Avatar answered Oct 24 '22 09:10

HunterCM


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

like image 2
Andrea Rosini Avatar answered Oct 24 '22 11:10

Andrea Rosini


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

like image 1
rpwc Avatar answered Oct 24 '22 10:10

rpwc