开发者

How do I draw a graph in my application?

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   
  开发者_StackOverflow中文版, 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);


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


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.


You should use AchartEngineAchartEngine

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜