<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    海上月明

    editer by sun
    posts - 162, comments - 51, trackbacks - 0, articles - 8
       :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

    將chartdirector創建的image嵌入網頁的兩種方法

    Posted on 2009-06-15 14:03 pts 閱讀(972) 評論(0)  編輯  收藏 所屬分類: Python
    這里詳細說明了在網頁中嵌入chartdirector元素的兩種方法

    Django integration
    Posted by GMalla on Mar-02-2008 23:28
    Hi,
      I'm using Django framework for my web application. How do i integrate chart director with Django custom views. In Django views define context and the context is passed to a html template. Html template creates output html file. My question is how to I pass a parameter to <IMG SRC="/home/simplebar.py"> . Because in Django the URLs do not end with .py extension. This again need to be mapped to a view function. I'm bit confuse.
    Please help.

    Thanks
    GMalla

      Re: Django integration
    Posted by Peter Kwan on Mar-03-2008 13:31
    Hi GMalla,

    I have never used Django before. However, I have seen many frameworks, so I may provide some general ideas.

    There are two methods to output a chart in a web page.

    (1) Create the chart as an image file, then output the image file. For example, if you are using the sample code in "pythondemo/simplebar.py" (*not* the CGI one), it is creating the chart as a file "simplebar.png". So after crreating the chart, in your <IMG> tag, you may use <IMG SRC="/path/to/simplebar.png">.

    If you use this method, the followings are several important things to note:

    - To avoid confusion, you should use the full path name, not a relative path name. Some web frameworks will use some strange directory as the "current working directory", and your relative path name may end up relative to some strange place.

    - Please be aware the path in the "makeChart" call is a file system path name, not a URL path. For example, "/aaa,png" means storing "aaa.png" in the root of the hard disk, not the root of your web directory. (Of course, the <IMG> tag path is a URL, as per HTML standard.)

    - Make sure your web server has read and write access to the directory. By default, the web server, usually running as the anonymous user, may not write to the hard disk. For testing, you may want to set the directory to be readable and writable to anyone.

    - The sample code uses a hard coded file name "simplebar.png". For a web server, you may want to use a unique file name, otherwise two users accessing the server at the same time will overwrite each other's files. The BaseChart.makeTmpFile method in ChartDirector may be useful for this purpose.


    (2) Another method is to create the chart as an image in memory, then stream the image to the browser. Most well-developed web framework supports streaming of non-HTML content, such as images, movies, etc.. In the "pythondemo_cgi/simplebar.py" sample code, the following method is used to stream the content to the browser:

    print "Content-type: image/png\n"
    binaryPrint(c.makeChart2(PNG))

    For your Django framework, you may need to read the Django documentation, or post questions to Django support or Django forum to ask if Django can stream non-HTML content. If it can, then you may replace the above two lines with the Django streaming code. In this case, the <IMG> tag is <IMG SRC="/path/to/yourDjangoCode.xxx"> where yourDjangoCode.xxx is the Django code that creates the chart and streams it to the browser.

    If Django does not support non-HTML content, then you must use method (1) above.


    Hope this can help.

    Regards
    Peter Kwan

      Re: Django integration
    Posted by Adrian on Mar-24-2008 09:28
    A quick Django integration:

    1) Add your URL pattern:
    url(r'^test.png$', views.test, name='url_chart_test'),

    2) create your view function:

    from django.http import *
    from pychartdir import *

    def test(request):
        data = [85, 156, 179.5, 211, 123]
        labels = ["Mon", "Tue", "Wed", "Thu", "Fri"]
        c = XYChart(250, 250)
        c.setPlotArea(30, 20, 200, 200)
        c.addBarLayer(data)
        c.addBarLayer(data)

        response = HttpResponse( mimetype='image/png')
        response.write(c.makeChart2(PNG))

        return response

    3) in your html page, add a link to this "image"
    <img src="/whatever/test.png">


    主站蜘蛛池模板: 一区二区无码免费视频网站| 久久亚洲2019中文字幕| 激情小说亚洲图片| 亚洲色大成网站WWW久久九九| 无码A级毛片免费视频内谢| 亚洲欧美aⅴ在线资源| 亚洲一区二区三区偷拍女厕| 亚洲一区二区三区免费在线观看| 亚洲AV网一区二区三区| 亚洲AV无码乱码在线观看裸奔| 无码一区二区三区AV免费| 二区久久国产乱子伦免费精品| 亚洲免费二区三区| 国产亚洲精品福利在线无卡一| 成人毛片免费视频| 东方aⅴ免费观看久久av | 在线亚洲97se亚洲综合在线| 蜜臀98精品国产免费观看| 少妇亚洲免费精品| 亚洲情A成黄在线观看动漫软件| 亚洲午夜福利717| 国产中文字幕免费观看| 国产成人精品免费午夜app | 无码精品A∨在线观看免费| 一个人免费播放在线视频看片| 亚洲欧洲高清有无| 亚洲区小说区激情区图片区| 精品剧情v国产在免费线观看| 巨波霸乳在线永久免费视频| 国产无限免费观看黄网站| 亚洲av最新在线观看网址| 亚洲黄色高清视频| 亚洲gv猛男gv无码男同短文| 免费一级特黄特色大片在线| 一个人在线观看视频免费| 啦啦啦完整版免费视频在线观看| 四虎影视无码永久免费| eeuss免费天堂影院| 深夜特黄a级毛片免费播放| 亚洲伊人久久大香线蕉AV| 亚洲国产精品综合久久2007|