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`
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.
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
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With