Discussion Board

Results 1 to 4 of 4

Thread: Graph drawing

  1. #1
    Registered User
    Join Date
    Sep 2007

    Graph drawing

    hi to all frnds
    i want to draw a graph in my mobile by using diff values can anyone help for this application?
    Keyur Tank, B.E.I.T
    Gujrat, India

    Pys-60 1.4.0 with Nokia N-72
    Symbian C++,Python

  2. #2
    Nokia Developer Moderator
    Join Date
    May 2007
    21.46 N 72.11 E

    Re: Graph drawing

    I think you havent checked the Wiki yet...

    Here is the code

    from __future__ import generators
    def arange(start, stop=None, step=None):
        if stop is None:
            stop = float(start)
            start = 0.0
        if step is None:
            step = 1.0
        cur = float(start)
        while cur < stop:
            yield cur
            cur += step
    from appuifw import *
    app.body = canvas = Canvas()
    width, height = canvas.size
    def axes(xyrange, position=[18, height-11, width-10, 10], formatter=lambda x:x):
        global left, bottom, right, top, min_x, min_y, scale_x, scale_y
        left, bottom, right, top = position
        min_x, max_x, step_x, min_y, max_y, step_y = xyrange
        scale_x = float(right-left)/(max_x-min_x)
        scale_y = float(bottom-top)/(max_y-min_y)
        canvas.rectangle([(left,top), (right+1, bottom+1)], 0)
        for x in arange(min_x, max_x, step_x):
            canvas.text((14+scale_x*(x-min_x), height-1), unicode(formatter(x)))
            canvas.point((left+scale_x*(x-min_x), bottom-1), 0)
            canvas.point((left+scale_x*(x-min_x), top+1), 0)
        for y in arange(min_y, max_y, step_y):
            canvas.text((2, bottom+2-scale_y*(y-min_y)), unicode(formatter(y)))
            canvas.point((left+1, bottom-scale_y*(y-min_y)), 0)
            canvas.point((right-1, bottom-scale_y*(y-min_y)), 0)
    def plot(xs, ys=None):
        if ys==None:
            ys = xs
            xs = range(len(ys))
        last = left+(xs[0]-min_x)*scale_x, bottom-(ys[0]-min_y)*scale_y
        for i in range(1, len(ys)):
            p = left+(xs[i]-min_x)*scale_x, bottom-(ys[i]-min_y)*scale_y
            canvas.line([last, p], 0x00000ff)
            last = p
        canvas.point(last, 0x0000ff)
    axes([0,3.1,.5, 1,4.1,.5])
    The Above code plots a straight line.You can change the 2 commands at ends and get a graph of your choice.

    Hope that helps
    Last edited by croozeus; 2007-09-27 at 17:14.
    Pankaj Nathani

  3. #3
    Super Contributor
    Join Date
    May 2006
    Oulu, Finland

    Re: Graph drawing

    Hi sam_tank and welcome to the forum

    Check the canvas object on the PyS60 doc. There you'll see all the different objects you can draw on it and their attributes.

    To croozeus. Use the code tag (# button) to post some source code and not QUOTE; it keeps the indents. So please edit your previous post to make the modification that we can read properly your source example.

    Nokia E61 3rd Edition - pys60 1.4.0

    Tips and modules:

  4. #4
    Nokia Developer Moderator
    Join Date
    May 2007
    21.46 N 72.11 E

    Re: Graph drawing


    Sorry Mate i had given a quick reply. I will be careful next time.
    Pankaj Nathani

Similar Threads

  1. Graph Drawing
    By alonish in forum Mobile Java General
    Replies: 1
    Last Post: 2005-12-03, 19:48
  2. How to draw a graph???
    By zikman23 in forum Symbian
    Replies: 1
    Last Post: 2005-01-28, 04:06
  3. Drawing Primitives
    By ManishPatil in forum Symbian
    Replies: 0
    Last Post: 2004-07-14, 16:45
  4. Which one is the fastest (in drawing) ?
    By Smori2002 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2003-11-12, 15:36
  5. Offscreen drawing and cursor
    By tolnaisz in forum Symbian
    Replies: 0
    Last Post: 2003-05-12, 17:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts