Android GraphView 2 without labels

笑着哭i 提交于 2019-12-11 06:59:46

问题


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.

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>

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

Thank you very much for any help,

Matthias


回答1:


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




回答2:


I had the same problem. This can be solved by removing the following line from the manifest file.

 android:theme="@style/AppTheme"

I know this is quite vague, but worked for me. I don't the exact reason why this happens. If u guys come across the better solution please do share it.




回答3:


You should use the latest version from github and include that in your project. This will allow you to set various colours using

graphView.getGraphViewStyle().setGridColor(Color.GREEN);
graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW);
graphView.getGraphViewStyle().setVerticalLabelsColor(Color.RED);


来源:https://stackoverflow.com/questions/8551548/android-graphview-2-without-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!