如何在我的应用程序中绘制图表?

发布于 2024-11-26 10:18:08 字数 912 浏览 3 评论 0原文

我需要将图表合并到我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情仇皆在手 2024-12-03 10:18:08

在调用 setContentView 方法后,您应该将其放入 Activity 的 onCreate 方法中。

You are supposed to put it in your onCreate method of your activity after you call setContentView method.

鯉魚旗 2024-12-03 10:18:08

这个库有问题,因为没有 Javadoc,你必须通过阅读源代码来弄清楚如何使用它。您可能会遇到与 GraphViewData 相关的编译错误,因为您应该显式导入嵌入 GraphView 类中的此类:

import com.jjoe64.graphview.GraphView.GraphViewData;

如果不“破解源代码”,您也无法拥有黑色文本、白色背景配色方案。它假设您只需要浅色文本、黑色背景图形。

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:

import com.jjoe64.graphview.GraphView.GraphViewData;

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.

遮了一弯 2024-12-03 10:18:08

您应该使用 AchartEngineAchartEngine

它适合在 android 中制作任何类型的图表和图形..它可能对您有帮助...!

You should use AchartEngineAchartEngine

its good for making any type of chart and graphs in android..it may be helpful to you...!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文