我已经添加了GraphView对象,并根据网站文档中的示例向其中填充了一些数据。虽然我发现了如何更改GraphView的背景颜色,但我不知道如何更改网格颜色。有任何想法吗?

这是我尝试过的:

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);
}

最佳答案

尝试

        graph.getGridLabelRenderer().reloadStyles();


样式示例在这里
https://github.com/appsthatmatter/GraphView-Demos/blob/master/app/src/main/java/com/jjoe64/graphview_demos/examples/StylingColors.java

关于java - 在Android中更改GraphView对象的网格颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32085210/

10-09 05:14