开发者

PHP or Python for creating webcharts after calculations?

开发者 https://www.devze.com 2023-01-15 10:31 出处:网络
Is it a good idea to开发者_JS百科 code such a script in Python and in which language is handy for fast performance and useful libraries/frameworks for charts?(charts would be created after calculating

Is it a good idea to开发者_JS百科 code such a script in Python and in which language is handy for fast performance and useful libraries/frameworks for charts?(charts would be created after calculating an expression which is input from the user)

EDIT:It's a web server-side script


I'm not exactly sure what you mean by "charts", but if you mean plotting/creating graphs, perhaps you should look at R, a free software environment for statistical computing and graphics. It has good graphics capabilities, and can connect to many environments, including Python.


For Python - check matplotlib - it should do everything you need to do, including outputting to PNG, JPEG, etc.


It's reasonably straightforward to generate graphics on the fly in python using the reportlab library http://www.reportlab.com/software/opensource/. It includes functionality to create bar, line, pie, etc. charts from lists of data. Don't be misled by the emphasis on generating PDFs, the library also can create just PNG or GIF images. Also, the official documentation is very verbose and intimidating, but it's quite accessible once you actually start coding.

The following page explains the whole process for Django, but the same approach would be applicable to any framework: http://code.djangoproject.com/wiki/Charts.

In particular, note that you can build a graphic in-memory and return it as an HttpResponse. It's quite fast. I use something like the following in one of my apps:

def my_chart(request):
    response = HttpResponse(
        my_function_to_make_a_chart().asString('png'),
        'image/png',
    )
    return response

That django view would be associated with a URL that you would embed directly into your HTML document as an tag:

<img src="/my_site/my_chart/" alt="A cool chart" />
0

精彩评论

暂无评论...
验证码 换一张
取 消