Luke Allison
Luke Allison

Reputation: 3218

Changing the grid colour of a GraphView object in Android

I've added a GraphView object and populated it with some data as per the example in the documentation on the website. While I've found out how to change the background colour of the GraphView, I have no idea how to change the grid colour. Any ideas?

This is what I've tried:

public void createGraph(View view){
    GraphView graph = (GraphView) view.findViewById(R.id.graph);
    GridLabelRenderer gridLabelRenderer = graph.getGridLabelRenderer();

    // This works
    graph.setBackgroundColor(getResources().getColor(android.R.color.holo_green_light));

    // This does not work
    gridLabelRenderer.setGridColor(getResources().getColor(android.R.color.holo_green_light));

    // Nor does this
    //gridLabelRenderer.setGridColor(15);

    // This works
    LineGraphSeries<DataPoint> series = new LineGraphSeries<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);
}

Upvotes: 1

Views: 2716

Answers (1)

appsthatmatter
appsthatmatter

Reputation: 6417

try

        graph.getGridLabelRenderer().reloadStyles();

styling example it here https://github.com/appsthatmatter/GraphView-Demos/blob/master/app/src/main/java/com/jjoe64/graphview_demos/examples/StylingColors.java

Upvotes: 2

Related Questions