How to draw the chart

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

How to draw the chart

Postby rakesh86shankar » Wed Feb 10, 2010 2:16 pm

Hi ,i want to draw a chart of this type,how to do it,I tried it.Is there any simple charts like this,pie chart etc

how to do it





Image
rakesh86shankar
Developer
Developer
 
Posts: 38
Joined: Fri May 29, 2009 9:51 am

Top

Postby zorro » Wed Feb 10, 2010 3:03 pm

You cand use Canvas class and it's drawing functions. The one that suits your need it's the old basic DrawLine:

public void drawLine (float startX, float startY, float stopX, float stopY, Paint p);

First you draw the axis, two lines, then the values across the line. The data which must apper in the chart is stored in some way in memory. All you have to do is convert this values into the units of the chart. For example you decide that for Y axe 1 pixel is 10 units (10 pixels = 100 units, as an example to your picture). Same goes for X axis too. So you scale your data by a factor of 0.1 (divide by 10.0) to obtain the Y coord in pixels relative to the chart origin.

For pie charts you can use Arc and Oval shapes.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby whitecloud » Thu Feb 11, 2010 10:39 pm

Similar problem. I have ten number which I wish to use them to draw a beautiful chart.

Will it be easier if using OpenGL to draw line chart or bar chart? If yes, how to do it.

I am new, drawing it by self is too complicated for the novice like me. :)

Thanks in advance.
whitecloud
Freshman
Freshman
 
Posts: 5
Joined: Thu Feb 11, 2010 10:13 pm

Postby zorro » Fri Feb 12, 2010 11:46 am

I suggest you to take an android sample from the SDK that draws something on the screen using Canvas class and try to understand it (look up for the the initialization of the activity and the canvas class then the function that does all the drawing, etc). After that, all you have to do is do your stuff with lines, rectangles, circles, etc. It's not really complicated, but you have to start from somewhere, that's why i suggest you to load, compile and understand a sample from the SDK.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

How to draw the chart

Postby rakesh86shankar » Sat Feb 13, 2010 6:14 am

Hello Sir,can u tell me which sample pgm to refer,so that i can get an idea of it
rakesh86shankar
Developer
Developer
 
Posts: 38
Joined: Fri May 29, 2009 9:51 am

Postby zorro » Sat Feb 13, 2010 1:37 pm

For a working Canvas example you can look at the Lunar Lander demo.
The path is: android-2.0.1 > samples > LunarLander

For other graphic examples, you cand search and read from the source files found here:
android-2.0.1 > samples > ApiDemos > src > com > example > android > apis > graphics
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests