Android的GraphView 2没有标签 [英] Android GraphView 2 without labels

查看:94
本文介绍了Android的GraphView 2没有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为Android应用程序中绘制图形。我发现这个库被称为GraphView(http://www.jjoe64.com/p/graphview-library.html)。我目前使用的版本2,这是可以在GitHub上。

I am currently trying to draw a graph within an Android application. The library I found is called GraphView (http://www.jjoe64.com/p/graphview-library.html). I am currently using version 2, which is available on GitHub.

绘制图表的作品真的很好。要得到一个图形中的code是以下内容:

Drawing graphs works really nicely. The code necessary to get a graph is the following:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Map<String,List<GraphEntry>> graphData = (...)

    if (graphData != null) {
        List<GraphEntry> entries = graphData.get("temperature");
        GraphView.GraphViewData[] data = new GraphView.GraphViewData[entries.size()];

        int i = 0;
        for (GraphEntry entry : entries) {
            data[i++] = new GraphView.GraphViewData(entry.getDate().getTime(), entry.getValue());
        }
        GraphView.GraphViewSeries graphViewSeries = new GraphView.GraphViewSeries("temperature", 0xffff0000, data);
        LineGraphView graphView = new LineGraphView(this, "temperature");
        graphView.addSeries(graphViewSeries);
        graphView.setShowLegend(true);

        LinearLayout graphLayout = (LinearLayout) findViewById(R.id.layout);
        graphLayout.addView(graphView);
    }
}

这将产生一个正常的图表。不幸的是,各种标签丢失。文档讲述,对于正常使用情况下,人们不必在意标签,因为库会自动完成。我究竟做错了什么?我只得到纯图形,没有任何标签。

This will produce a normal graph. Unfortunately, all kinds of labels are missing. The documentation tells that for the normal use case, one does not have to care about labels, as the library does this automatically. What am I doing wrong? I only get the plain graph, without any labels.

有关的完整性,我加入了图形线性布局。适当的布局文件中有如下内容:

For the completeness, I am adding the graph to a linear layout. The appropriate layout file has the following contents:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="fill_parent"
          android:padding="5dp"
          android:id="@+id/layout"
          android:orientation="vertical"
    ></LinearLayout>

该GraphEntry类是只能用java.util.Date属性和双重价值属性的容器。

The GraphEntry class is only a container with a java.util.Date attribute and a double value attribute.

非常感谢你的帮助,

马蒂亚斯

推荐答案

我切换到另一个图表引擎: AChartEngine 。这一次开箱的。

I switched to another charting engine: AChartEngine. This one works out of the box.

这篇关于Android的GraphView 2没有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆