如何在我的应用程序中绘制图表?
我需要将图表合并到我的 Android 应用程序中,我正在尝试遵循本教程:
http://www.jjoe64.com/2011/07/chart-and-graph-library-for-android.html
我尝试将其放入我的活动类中,它显示大量与 GraphView 相关的错误。以下是代码片段:
// graph with dynamically genereated horizontal and vertical labels
GraphView graphView = new GraphView(
this // context
, new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(2.5, 3.0d) // another frequency
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
, new GraphViewData(5, 3.0d)
} // data
, "GraphViewDemo" // heading
, null // dynamic labels
, null // dynamic labels
);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
I need to incorporate a graph into my android application, I am trying to follow this tutorial:
http://www.jjoe64.com/2011/07/chart-and-graph-library-for-android.html
I tried putting it into my activity class and it shows up with a ton of errors related to GraphView
. Here are the snippets of code:
// graph with dynamically genereated horizontal and vertical labels
GraphView graphView = new GraphView(
this // context
, new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(2.5, 3.0d) // another frequency
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
, new GraphViewData(5, 3.0d)
} // data
, "GraphViewDemo" // heading
, null // dynamic labels
, null // dynamic labels
);
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
layout.addView(graphView);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在调用 setContentView 方法后,您应该将其放入 Activity 的 onCreate 方法中。
You are supposed to put it in your onCreate method of your activity after you call setContentView method.
这个库有问题,因为没有 Javadoc,你必须通过阅读源代码来弄清楚如何使用它。您可能会遇到与 GraphViewData 相关的编译错误,因为您应该显式导入嵌入 GraphView 类中的此类:
如果不“破解源代码”,您也无法拥有黑色文本、白色背景配色方案。它假设您只需要浅色文本、黑色背景图形。
This library has issues, because there is no Javadoc and you have to figure out how to use it by reading the source code. You may get compile errors relating to GraphViewData, because you are supposed to explicitly import this class embedded within the GraphView class:
You also cannot have a black text, white background colour scheme without "hacking the source code". It assumes you need only light text, black background graphs.
您应该使用 AchartEngineAchartEngine
它适合在 android 中制作任何类型的图表和图形..它可能对您有帮助...!
You should use AchartEngineAchartEngine
its good for making any type of chart and graphs in android..it may be helpful to you...!