Ido Naveh
Ido Naveh

Reputation: 2492

How to replace the numbers on the bottom of Bar GraphView with strings?

I'm using jjoe64 GraphView library for creating a bar GraphView in my app.

When I'm creating a new DataPoint, it requires 2 values: X int, and a Y int, like this:

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

What can I do to replace the X int on the bottom with Strings?

EDIT #1

By bottom I mean this part where said 0, 0.5, 1...

Upvotes: 1

Views: 599

Answers (1)

Psytho
Psytho

Reputation: 3384

What you call "bottom" is "X-axis". To label it use

StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"});
graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);

Further reading: Documentation

Or if you use GraphView 3.x:

graphView.setHorizontalLabels(new String[] {"0.5", "1", "1.5", "2.0"});

Upvotes: 4

Related Questions