0

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:

enter image description here

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?

shawkinaw
  • 3,190
  • 2
  • 27
  • 30

2 Answers2

3

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)
appsthatmatter
  • 6,347
  • 3
  • 36
  • 40
1

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.

Community
  • 1
  • 1
gknicker
  • 5,509
  • 2
  • 25
  • 41
  • How can I use this to add padding, since `formatLabel` just returns a string? Are you suggesting that I pad by adding spaces to the returned string? – shawkinaw Jan 28 '15 at 22:02
  • Yes, adding spaces for x-axis labels and possibly newline characters for y-axis is the only answer I've found. All of the GraphView examples have the labels crammed up against the graph, and none of those examples include any solution for this. Note the other answer I referenced, where a different graph library is recommended. – gknicker Jan 28 '15 at 22:46