所有组件:http://gallery.pyecharts.org/#/README
使用基础API:http://pyecharts.org/#/zh-cn/intro
Pyecharts安装:pip install pyecharts
中国地图、世界地图包:
$ pip install echarts-countries-pypkg
$ pip install echarts-china-provinces-pypkg
$ pip install echarts-china-cities-pypkg
$ pip install echarts-china-counties-pypkg
$ pip install echarts-china-misc-pypkg
$ pip install echarts-united-kingdom-pypkg
Django与Pyecharts基础应用:正常简历APP,然后建立模板文件夹,正常建立路由和视图,最后可以复制Pyecharts的组件:
组合组件:柱状图、线型图
from django.http import HttpResponse from pyecharts import options as opts from pyecharts.charts import Bar, Grid, Line from pyecharts.faker import Faker from pyecharts.globals import ThemeType def echarts_basic(request): bar = ( Bar() .add_xaxis(Faker.choose()) .add_yaxis("商家A", Faker.values()) .add_yaxis("商家B", Faker.values()) .set_global_opts( title_opts={"text": "Bar-通过 dict 进行配置", "subtext": "我也是通过 dict 进行配置的"} ) ) line = ( Line() .add_xaxis(Faker.choose()) .add_yaxis("商家A", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) .add_yaxis("商家B", Faker.values(), areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) .set_global_opts( title_opts=opts.TitleOpts(title="Line-面积图", pos_top="48%"), legend_opts=opts.LegendOpts(pos_top="48%"), ) ) grid = ( # 13种样式 # Grid(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.DARK)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.CHALK)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.ESSOS)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.INFOGRAPHIC)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.MACARONS)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.ROMA)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.ROMANTIC)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.SHINE)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.WALDEN)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS)) # Grid(init_opts=opts.InitOpts(theme=ThemeType.WONDERLAND)) Grid(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS)) .add(bar, grid_opts=opts.GridOpts(pos_bottom="60%")) .add(line, grid_opts=opts.GridOpts(pos_top="60%")) .render("./Pyecharts/templates/r.html") ) return HttpResponse(grid)
当用浏览器浏览地址的时候会自动生成html文件。可以修改html里的样式,也可以在Pyecharts里根据API自定义相关样式。