在 GraphView 中的图形和刻度标签之间添加 space?

Add space between graph and tick labels in GraphView?

我正在试用 GraphView Library 在 Android 上创建图表。它看起来相当不错,但我想知道是否有办法在刻度标签和图形本身之间添加一些 space 。如您所见,基本上有 none:

我使用下面的代码来设置图形(非常类似于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);

我尝试使用 graph.getGridLabelRenderer().setPadding(),但这只是在整个图表周围添加了填充。

那么,有没有办法在这些标签周围添加一些填充?

按照此示例为您的图形提供自定义标签格式化程序。通过这样做,您至少可以添加 space 填充到您的 y 轴标签(如果不是换行间距到您的 x 轴标签)。

// 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) + " €";
            }
        }
    }
);

我从 GraphView documentation 中提取了这个例子。

另外,我发现有人选择 this answer 作为类似问题的最佳回答,这很有趣。

是的,在 github 的当前版本中是可能的(将在 4.0.1 中发布)。 有方法:

graph.getGridLabelRenderer().setLabelsSpace(x)