[Zope] Using pychart from a Zope product

Reuven M. Lerner reuven at lerner.co.il
Wed Jan 26 14:37:12 EST 2005


Hi, Dieter.  You wrote:

>You are missing that we need your piece of code that interfaces
>"PyChart" with Zope. How do you pass the result of "PyChart"
>back to Zope/ZPublisher?
>
>  
>
For now, I just wanted to save the resulting chart to disk, just to see 
if the darned thing would produce any output.  My next question was 
going to be if there's a more intelligent way to integrate PyChart with 
Zope than saving charts to a directory that's exposed to the outside 
world via the Web.

The following is the method that I wrote in my Zope product, taken 
almost 100 percent from one of the demos that came with PyChart:

        def return_basic_chart(self, REQUEST):
            "Return a basic chart"

            can = canvas.init("/tmp/chart.pdf")

            # We have 10 sample points total.  The first value in each
    tuple is
            # the X value, and subsequent values are Y values for
    different lines.
            data = [(10, 20, 30), (20, 65, 33),
                    (30, 55, 30), (40, 45, 51),
                    (50, 25, 27), (60, 75, 30),
                    (70, 80, 42), (80, 62, 32),
                    (90, 42, 39), (100, 32, 39)]

            # The format attribute specifies the text to be drawn at
    each tick mark.
            # Here, texts are rotated -60 degrees ("/a-60"),
    left-aligned ("/hL"),
            # and numbers are printed as integers ("%d").
            xaxis = axis.X(format="/a-60/hL%d", tic_interval = 20,
    label="Stuff")
            yaxis = axis.Y(tic_interval = 20, label="Value")

            # Define the drawing area. "y_range=(0,None)" tells that the
    Y minimum
            # is 0, but the Y maximum is to be computed automatically.
    Without
            # y_ranges, Pychart will pick the minimum Y value among the
    samples,
            # i.e., 20, as the base value of Y axis.
            ar = area.T(x_axis=xaxis, y_axis=yaxis, y_range=(0,None))

            # The first plot extracts Y values from the 2nd column
            # ("ycol=1") of DATA ("data=data"). X values are takes from
    the first
            # column, which is the default.
            plot = line_plot.T(label="foo", data=data, ycol=1,
    tick_mark=tick_mark.star)
            plot2 = line_plot.T(label="bar", data=data, ycol=2,
    tick_mark=tick_mark.square)
           
            ar.add_plot(plot, plot2)

            # The call to ar.draw() usually comes at the end of a
    program.  It
            # draws the axes, the plots, and the legend (if any).
            ar.draw(can)

            return "drawn"

As I wrote in my previous note, the above code executes without any 
errors.  And I get the plain-text "drawn" in my Web browser when I go to 
the /return_basic_chart method via the browser.  But no chart is 
actually generated on disk, so far as I can tell.

If there's a better/smarter way to take PyChart output and display it 
via Zope, I'm all in favor.  And indeed, that's my eventual goal.  But 
right now, I'm concerned that I have a problem whose cause isn't 
obvious, but which might be indicative of something else.

Thanks again,

Reuven

>  
>


More information about the Zope mailing list