`
iamsk
  • 浏览: 70634 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

Open Flash Chart 在 Django 下的使用

阅读更多

Open Flash Chart 在 Django 下的使用

原由:最近公司分配任务,让做监控数据的可视化页面(应该属于报表一类吧)

开始先看了Open Flash Chart(http://teethgrinder.co.uk/open-flash-chart-2/),
官网的教材非常详细,并分了六个部分:
1、安装:
到此链接(http://teethgrinder.co.uk/open-flash-chart-2/downloads.php)下载最新版本
目前是Version 2 Kvasir (16th, June 2009),取其中:open-flash-chart.swf文件
无需安装,只用放在一个能被调用到的地方就行
HelloWorld实例:
copy主页提供的chart.html文件,和上面文件放一起,即可使用chart.html页面进行查看
此时,为错误页面,因为没有提供页面的配置数据
使用数据:
下载主页的data.json,放在以上相同目录下,使用chart.html?ofc=data.json
用户想要如何显示图表,都由这个json数据进行确定
即可查看
整个配置过程,就像配置fckeditor一样,并且更简单
整个流程是:
   1. The bowser requests chart.html
   2. It finds the flash tags and requests the open-flash-chart.swf flash application. Downloads it.
   3. Open Flash Chart looks in the URL for the data file. It downloads it.
   4. Open Flash Chart reads the JSON and displays the chart.
2、使用js库,进行配置
了解下swfobject(http://code.google.com/p/swfobject/)是很有好处的,尤其是他的传值那块
需要,swfobject.js库
实例:just download from the main page and test on your computer
3、data-file的使用
在动态页面里经常会用到这个,在这里最需要注意的是You MUST urlencode any parameter you
pass into swfobject,我就是在这里浪费了好多时间
4、使用php产生json数据,主要调用open-flash-chart.php这个文件里的函数,进行写json
5、6及其他 高层次js调用,借助ajax实现更强大的功能
图表样式见:Charts(http://teethgrinder.co.uk/open-flash-chart-2/area-hollow.php)
生成图表json数据类型及格式见:Chart Elements(http://teethgrinder.co.uk/open-flash-chart-2/x-axis.php)

介绍了这么多,该开始任务了
推荐:pyOFC2 Python Open Flash Chart 2 (http://btbytes.github.com/pyofc2/)
原因:整个系统首次使用图形展示,并且逻辑并不复杂,也是老大推荐的
Using PyOFC2 with Django
   1. Download Open Flash Chart 2
   2. Download and install PyOFC2
   3. Download SWFObject and put the files in your static media directory
   4. Add references to the SWFObject files and open-flash-chart.swf file in the header section. See templates/index.html for details
   5. Create a view to serve the json data from. See demoapp/views.py
   6. Configure urls.py to map the view to the url endpoint.
最简单的方法就是以djofc2为模板,改动即可
在第二步需要注意:安装时会自动安装python-cjson,在linux下没有问题,但是在win下会出现
cjson编译的版本与python的不同此问题,两种解决方法:first, 安装mingw,这个在以前装一个linux下
的python抓包库是也出现过这样的问题,需要下载很多安装包,包括gcc、g++等,此处要注意的是
不能用默认的gcc3.4而要自己下载个gcc4以上;second, 直接删掉pyofc2里setup.py中的require内容,
更改ofc2.py里的import cjson为import simplejson as cjson,并更改cjson.encode()为cjson.dumps()
更改方法多样,这只是一种
在第三步可以在django的url里建一个,staticserver目录,并将static下的文件放入其中
第四步见提供的templates/index.html模板,主要关注data-file后的链接,重点:因为这个链接需要encode的url,
可以使用django中的{% url value|encode %}(php因为可以调用系统函数,直接用encode即可),但此处django的管道功能太
简单了,无法实现带参数传递并encode(可能是我无法实现),经过多次测试,发现url中传的第一个参数总能被取到,而后面的参数直接
就被截断了,我试着将多个参数封装到一个变量中,中间用分隔符分开,试了": / \"等均不行,最后用"_"分隔实现了
因为在encode的url这块不太了解,导致花费了很多时间,现在要好好看看encode这块,及url的特殊字符等等
希望我遇到的问题能对大家有所帮助。

 

自iamsk7.appspot.com转移,2010-03-24,准备放弃自己做的blog ;)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics