Hi Massimo,
thank you for the *really* prompt reply!
I managed to have Dojox charts work, but I'm getting a error message
form the "matplotlib" code (btw, "import datetime" was missing). I
pasted the Dojo code at the bottom of this email, just in case I'm not
the only beginner around :)
Traceback (most recent call last):
File "/home/aus/Software/Web2py/web2py/gluon/restricted.py", line
62, in restricted
exec ccode in environment
File "/home/aus/Software/Web2py/web2py/applications/test/controllers/
matplotlib.py", line 29, in <module>
File "/home/aus/Software/Web2py/web2py/gluon/globals.py", line 55,
in <lambda>
self._caller=lambda f: f()
File "/home/aus/Software/Web2py/web2py/applications/test/controllers/
matplotlib.py", line 23, in simple
response.header['content-type']='image/png'
TypeError: 'NoneType' object does not support item assignment
what's wrong with the response?
thank you once again!
Cheers,
aus
Dojo / Dojox charting / JSON example:
<script type="text/javascript">
dojo.require("dojox.charting.Chart2D");
{{import gluon.contrib.simplejson as sj}}
function plott(){
//var dd = dojox.json.ref.fromJson(data);
//var data = [1,3,2,4,3,6];
console.debug({{=sj.dumps(data)}});
var chart1 = new dojox.charting.Chart2D("simplechart");
chart1.addPlot("default", {type: "Lines"});
chart1.addAxis("x");
chart1.addAxis("y", {vertical: true});
chart1.addSeries("Series 1", {{=sj.dumps(data)}});
chart1.render();
};
dojo.addOnLoad(plott);
</script>
On Dec 16, 3:49 pm, mdipierro <[email protected]> wrote:
> In web2py+matplotlib:
>
> def simple():
> import random, cStringIO
>
> from matplotlib.backends.backend_agg import FigureCanvasAgg as
> FigureCanvas
> from matplotlib.figure import Figure
> from matplotlib.dates import DateFormatter
>
> fig=Figure()
> ax=fig.add_subplot(111)
> x=[]
> y=[]
> now=datetime.datetime.now()
> delta=datetime.timedelta(days=1)
> for i in range(10):
> x.append(now)
> now+=delta
> y.append(random.randint(0, 1000))
> ax.plot_date(x, y, '-')
> ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
> fig.autofmt_xdate()
> canvas=FigureCanvas(fig)
> response.header['content-type']='image/png'
> stream=cStringIO.StringIO()
> canvas.print_png(stream)
> return stream.getvalue()
>
> Massimo
>
> On Dec 16, 6:12 am, aus <[email protected]> wrote:
>
> > Hi Massimo,
>
> > thank you for your reply. Your suggestion does not seem to work, but
> > maybe I'm not using Dojo properly. How would you code the plot with
> > flot?
>
> > Also, it would be great to be able to embed images/charts generated by
> > matplotlib, similarly to what can be done with
> > django:http://www.scipy.org/Cookbook/Matplotlib/Django. Is there a similar
> > feature in web2py?
>
> > Thank you!
>
> > Cheers,
> > aus
>
> > On Dec 16, 6:57 am, mdipierro <[email protected]> wrote:
>
> > > I do not know about Dojo. I have been using flot instead. perhaps this
> > > helps
>
> > > {{import gluon.contrib.simplejson as sj}}
> > > {{=sj.dumps(data)}}
>
> > > data will be printed in the page in json format. If your view/template
> > > includes javascript code you can put the above statements in the js
> > > itself.
>
> > > Perhaps other users can help more.
>
> > > Massimo
>
> > > On Dec 15, 11:31 pm, aus <[email protected]> wrote:
>
> > > > Hi everybody,
>
> > > > although I have some experience with programming, javascript/AJAX is
> > > > completely new to me. I'm very happy with web2py and I'm trying now to
> > > > pass arrays and possibly more structured data to Dojox to plot series
> > > > computed in python using Dojox's charts. How can I do that? I somehow
> > > > cannot cross the wall between the templace code and the javascript
> > > > code... Is JSON a possible solution? Could someone provide an example?
>
> > > > thank you!
>
> > > > Cheers,
> > > > aus
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---