dynamic chart creation (CP 2.2)

68 views
Skip to first unread message

dimitri pater

unread,
Nov 2, 2006, 5:43:56 PM11/2/06
to cherryp...@googlegroups.com
Hi,
maybe someone here cab give me a clue on how to accomplish the following:
on http://www.serpia.org/water I am running a test with ChartDirector, this page includes a form that trggers the action "../makeGraph"
makeGraph is something like this:

        def makeGraph(self, howmuch):
            # create a random string and concenate it to png
            ...
            # check values
            ...
            # Create the chart with ChartDirector
            ....
           
            # The data for the bar chart
            c.makeChart("../charts/"+a+"")
           
            result = []
            result.append('<h1>Reporting the results!</h1>')
            result.append('<img src="../charts/%s">' % a)
            return '\n'.join(result)
        makeGraph.exposed = True

So that the chart gets a random name and is diplayed on the webpage.
But, what I really want to do is displaying the chart on the ../water page (where the form also is)
I have tried doing a redirect from ../makeGraph to /water in stead of returning the result, but that only works if the filename is always the same (using <img=" chart.png">. But I need a random name every time a Chart is created.
Any idea? Your help is appreciated!

Dimitri
--
---
You can't have everything. Where would you put it? -- Steven Wright
---
please visit www.serpia.org

Tim Roberts

unread,
Nov 2, 2006, 6:20:26 PM11/2/06
to cherryp...@googlegroups.com
dimitri pater wrote:
> Hi,
> maybe someone here cab give me a clue on how to accomplish the following:
> on http://www.serpia.org/water I am running a test with ChartDirector,
> this page includes a form that trggers the action "../makeGraph"
> makeGraph is something like this:
>
> def makeGraph(self, howmuch):
> # create a random string and concenate it to png
> ...
> # The data for the bar chart
> c.makeChart("../charts/"+a+"")
>
> result = []
> result.append('<h1>Reporting the results!</h1>')
> result.append('<img src="../charts/%s">' % a)
> return '\n'.join(result)
> makeGraph.exposed = True
>
> So that the chart gets a random name and is diplayed on the webpage.
> But, what I really want to do is displaying the chart on the ../water
> page (where the form also is)
> I have tried doing a redirect from ../makeGraph to /water in stead of
> returning the result, but that only works if the filename is always
> the same (using <img=" chart.png">. But I need a random name every
> time a Chart is created.
> Any idea? Your help is appreciated!

There are several ways. One way is to have an <iframe> to hold your
chart, have some Javascript that refreshes it when the user hits <submit>.

Another way is to use something like AJAX to fetch the file name, and
modify the <img> tag on the fly to insert the new filename.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Christian Wyglendowski

unread,
Nov 2, 2006, 6:47:14 PM11/2/06
to cherryp...@googlegroups.com
On 11/2/06, Tim Roberts <ti...@probo.com> wrote:

dimitri pater wrote:
> Any idea? Your help is appreciated!

There are several ways.  One way is to have an <iframe> to hold your
chart, have some Javascript that refreshes it when the user hits <submit>.

Another way is to use something like AJAX to fetch the file name, and
modify the <img> tag on the fly to insert the new filename.

 Those are both good ways.  I think you could also make the form action on the /water page *be* the /water page, and then have your CherryPy handler for /water perform different actions depending on whether the request method was GET or POST.  On a GET, just display the form; on a POST, load the image and stick it in the page (and optionally redisplay the form).

Personally, I like Tim's suggestions better, but I thought I would throw this out there.

Christian
http://www.dowski.com


dimitri pater

unread,
Nov 3, 2006, 6:59:10 AM11/3/06
to cherryp...@googlegroups.com
Thanks for your suggestions both! Got it working now, not perfect but getting there...
thanks,
Dimitri
Reply all
Reply to author
Forward
0 new messages