android graph-view y axis numbers being cut out

做~自己de王妃 提交于 2019-12-23 09:00:34

问题


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`

回答1:


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.




回答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




回答3:


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




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/36231032/android-graph-view-y-axis-numbers-being-cut-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!