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

标签 android android-graphview

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

我看到了这个链接但不起作用: GraphView and resetData

我在 Activity 中绘制图表的代码:

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 项目,有一个工作示例。

关于android - 如何在 Android 中使用 GraphView 重绘图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21856041/

相关文章:

android - 如何在graphview中自定义网格比例?

android - 在 android WebView 中读取安全 cookie

android - 如何在android中为自定义键盘的特定键添加不同的状态

java - JJOE64 GraphView 库

java - 如何使用Arraylist填充Graphview折线图

android - MPAndroid 图表中的自定义 x 轴标签

android - 我应该将 GraphViewSeries 保存到 savedInstanceState 吗?

android - 如何使用 JNI 将 C++ 文件集成到 Android 应用程序中

android - NavigationView 项目选择未在选项卡更改时更新

android.view.WindowLeaked 异常