没有标签的Android GraphView 2
我目前正试图在Android应用程序中绘制一个图表。我找到的图书馆叫GraphView(http://www.jjoe64.com/p/graphview-library.html). 我目前正在使用GitHub上提供的版本2 绘制图形非常好。获取图形所需的代码如下:没有标签的Android GraphView 2,android,graph,plot,label,Android,Graph,Plot,Label,我目前正试图在Android应用程序中绘制一个图表。我找到的图书馆叫GraphView(http://www.jjoe64.com/p/graphview-library.html). 我目前正在使用GitHub上提供的版本2 绘制图形非常好。获取图形所需的代码如下: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Map<
@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);
}
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
映射图数据=(…)
if(graphData!=null){
列表条目=graphData.get(“温度”);
GraphView.GraphViewData[]数据=新的GraphView.GraphViewData[entries.size()];
int i=0;
用于(GraphEntry条目:条目){
数据[i++]=新的GraphView.GraphView数据(entry.getDate().getTime(),entry.getValue());
}
GraphView.GraphView系列GraphView系列=新GraphView.GraphView系列(“温度”,0xffff0000,数据);
LineGraphView graphView=新LineGraphView(该“温度”);
graphView.addSeries(graphView系列);
graphView.setShowLegend(真);
LinearLayout graphLayout=(LinearLayout)findViewById(R.id.layout);
graphLayout.addView(graphView);
}
}
这将生成一个法线图。不幸的是,各种标签都丢失了。文档告诉我们,对于正常用例,不必关心标签,因为库会自动这样做。我做错了什么?我只得到平面图,没有任何标签
为了完整性,我将图形添加到线性布局中。适当的布局文件包含以下内容:
<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属性和双值属性的容器
非常感谢您的帮助
Matthias我切换到另一个图表引擎:。这个是现成的。我也有同样的问题。这可以通过从清单文件中删除以下行来解决
android:theme="@style/AppTheme"
我知道这很模糊,但对我来说很有效。我不知道发生这种情况的确切原因。如果你们遇到更好的解决方案,请分享。您应该使用github的最新版本,并将其包含在您的项目中。这将允许您使用设置各种颜色
graphView.getGraphViewStyle().setGridColor(Color.GREEN);
graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW);
graphView.getGraphViewStyle().setVerticalLabelsColor(Color.RED);
您是如何在您的项目中实现此图形库的..?您好。我用了阿卡替林()。您将发现关于如何在应用程序中实现它的非常好的教程。马蒂亚斯