The paper is short and long, and the story is still young, my story is still about you
Recently, in the process of developing web applications, visual display functions were needed, so I found a Python-related visualization module. Here is a simple record of the usage of the pyecharts module. It is recommended mainly because of its powerful features, more choice of visualization features, and easier to use.
First need to understand the operating mechanism of the pyecharts module, pyecharts is echarts python-api, and echarts is Baidu open source visualization framework. Echarts is used to manipulate js files, so the emergence of pyecharts is actually to make the python language better echarts. Simply put, pyecharts will help us generate js files.
Or Github download source installation: https://github.com/pyecharts/pyecharts
Create a test.py file and write:
Running test.py will generate a render.html file in the current directory, which is the web page containing the histogram. Looking at this html file, you will find that it generates a lot of js code.
Note: In addition to the histogram, pyecharts supports other visual displays, please refer to the official documentation: http://pyecharts.org/#/zh-cn/charts
The previous introduction is to use pyecharts to generate an html page with a visual chart. How do you use it in a web framework such as Django or Flask? How do you generate chart code in the view layer and pass it to the template layer rendering display? Here only how to use pyecharts in Django, other web frameworks are the same, you can study it yourself.
Write in the view.py file of the Django project:
Description: REMOTE_HOST can replace the cost address, that is, go to the https://github.com/pyecharts/assets clone project, then copy the js directory in the project to the static/js directory of the Django project, and then change the REMOTE_HOST in the code. for:
Write the contents of the urls.py file in the Django project:
Create an index.html file in the templates directory of the Django project and write:
Open the browser: http://127.0.0.1:8000