繁体   English   中英

如何在Android中使用GraphView重绘图表

[英]How to Redraw chart with GraphView in Android

我使用这个库: https : //github.com/jjoe64/GraphView-Demos在我的应用程序中绘制图表。这个库是有效的,但是当我想绘制新图表或重绘时不起作用

我看到此链接但不起作用: GraphView和resetData

我在活动中绘制图表的代码:

GraphViewData[] newData = new GraphViewData[arrayWeight.size()];
    int i = 0;
    String date_now = "";

    for (Weight w : arrayWeight) {
        i += 1;
        date_now = w.getdate();
        date_now = date_now.substring(8);

        newData[arrayWeight.indexOf(w)] = new GraphViewData(
                Integer.parseInt(date_now), w.getWeight());

    }

    GraphViewSeries exampleSeries = new GraphViewSeries(newData);
    exampleSeries.resetData(newData);
    GraphView graphView = new LineGraphView(this, "weight");
    graphView.redrawAll();
    graphView.setVerticalLabels(new String[] { "100", "50", "1" });
    graphView.setShowLegend(true);
    graphView.setBackgroundColor(Color.GRAY);

    graphView.addSeries(exampleSeries); // data
    LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
    layout.addView(graphView);

如果要用新数据填充图形,则不必创建新的graphview对象,也不必创建新的graphviewseries对象。 只需使用resetData更改graphviewseries对象中的数据即可。 仔细研究GraphView-Demos项目,有一个有效的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM