Add space between graph and tick labels in GraphView?

六月ゝ 毕业季﹏ 提交于 2019-12-12 03:26:12

问题


I am trying out the GraphView Library for creating charts on Android. It looks quite decent, but I am wondering if there is a way to add some space between the tick labels and the graph itself. As you can see, there is basically none:

I use the following code to set up the graph (very similar to the example):

GraphView graph = (GraphView)view.findViewById(R.id.graph);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(new DataPoint[] {
    new DataPoint(0, 1),
    new DataPoint(1, 5),
    new DataPoint(2, 3)
});
graph.addSeries(series);

I tried using graph.getGridLabelRenderer().setPadding(), but that just added padding around the whole graph.

So, is there a way to put some padding around those labels?


回答1:


yes it is possible in the current version in github (will be released in 4.0.1). There is the method:

graph.getGridLabelRenderer().setLabelsSpace(x)



回答2:


Follow this example to give your graph a custom label formatter. By doing so, you can at least add space padding to your y-axis labels (if not newline spacing to your x-axis labels).

// GraphView 4.x
graph.getGridLabelRenderer().setLabelFormatter(
    new DefaultLabelFormatter() {
        @Override
        public String formatLabel(double value, boolean isValueX) {
            if (isValueX) {
                // show normal x values
                return super.formatLabel(value, isValueX);
            } else {
                // show currency for y values
                return super.formatLabel(value, isValueX) + " €";
            }
        }
    }
);

I pulled this example from the GraphView documentation.

Otherwise, I found it interesting that someone chose this answer as the best response for a similar question.



来源:https://stackoverflow.com/questions/28183486/add-space-between-graph-and-tick-labels-in-graphview

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