Node:Drawing on canvas, Next:, Previous:Creating canvas, Up:canvas



Drawing graphs on canvas

Pychart creates a new canvas object when "area.T:draw()" (see area) is called for the first time, and no canvas is yet created at that moment. You can thus use you own canvas by creating a canvas before calling the first area.T:draw, like below:

can = canvas.init("foo.pdf")
...
ar = area.T(...)
ar.draw()

You can also cause the same effect by passing the canvas object to the area.T:draw() method explicitly:

can = canvas.init("foo.pdf")
...
ar = area.T(...)
ar.draw(can)

Naturally, you can write to multiple files by passing multiple canvas objects to different area.T:draw(). For example, the below example draws the first chart to foo.pdf and the next chart to bar.pdf. The below example generates two files, graph1.pdf and graph2.pdf.

../demos/arrows.py

from pychart import *
import pychart.doc_support
import re
x = 100
y = 500

def draw(obj):
    global x, y
    name = pychart.doc_support.stringify_value(obj)
    name = re.sub("arrow\\.", "", name)
    obj.draw(((x, y), (x, y+30)))
    tb = text_box.T(text="/hC" + name, loc=(x, y-12), line_style=None)
    tb.draw()
    x = x + 50

for style in arrow.standards.list():
    draw(style)