Hi, everyone. I'm developing a Zope application that needs to do simple line-charts, and PyChart looks like a good solution to my problems. I was able to install PyChart without any trouble, and I also ran the command-line tests without any problems. But when I stick an example into a Zope product and invoke it, I get nothing -- not an error message, not an output chart, not a security violation of some sort... nothing at all. I know that PyChart is being invoked, because I can force an error by invoking theme.get_options(), which throws an error due to the lack of command-line options. I see from the various Zope mailing lists that people are using PyChart, and I have a feeling that I'm missing something obvious. But if someone has an idea regarding what I should be doing in order to get PyChart to work, I would greatly appreciate it. Thanks! Reuven
Reuven M. Lerner wrote at 2005-1-25 19:42 -0600:
.. But when I stick an example into a Zope product and invoke it, I get nothing -- not an error message, not an output chart, not a security violation of some sort... nothing at all. ... I see from the various Zope mailing lists that people are using PyChart, and I have a feeling that I'm missing something obvious.
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? Without this information, we (at least I) cannot help you. -- Dieter
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
Reuven M. Lerner wrote at 2005-1-26 13:37 -0600: [DM]
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... ... 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") ... ar = area.T(x_axis=xaxis, y_axis=yaxis, y_range=(0,None)) ... 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.
I expect that you must tell your canvas that it should write its content to disk (however, I do not know "Pychart").
If there's a better/smarter way to take PyChart output and display it via Zope, I'm all in favor.
There is "ZGDChart". It's a Zope interface to the "GDChart" package. Maybe, you look at it and how it exposes charts to Zope. -- Dieter
participants (2)
-
Dieter Maurer -
Reuven M. Lerner