在Android中更改GraphView对象的网格颜色

时间:2015-08-19 01:40:57

标签: java android android-graphview

我已经添加了一个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);
}

1 个答案:

答案 0 :(得分:1)