pyecharts 资料收集 记录
pip install pyecharts
https://github.com/pyecharts/pyecharts/
python 3.6 支持
https://gallery.pyecharts.org/#/
简介
https://pyecharts.org/#/zh-cn/intro
示例
https://gallery.pyecharts.org/#/README
百度官方 Echarts 官方实例
https://echarts.apache.org/examples/zh/
有的例子是 低版本的 ,
可以暂时 先安装 低版本的
python -m pip install pyecharts==0.5.11
2020年的例子是
pip install pyecharts==1.7.1
交流群
https://github.com/pyecharts/pyecharts/issues/1091
不错的一个应用
https://michaelguan.github.io/
运行示例 ----- 例子
移步至 pyecharts-gallery 的仓库
$ git clone https://github.com/pyecharts/pyecharts-gallery.git
# 如果未安装 pyecharts 请执行该语句安装
# pip install pyecharts
# 文件夹中有各种图和组件的 example,有其相对应的代码和 html 文件;自行调试
Pie - Customized_pie
https://gallery.pyecharts.org/#/Pie/customized_pie
官网有的东西
本指南介绍了如何在 Flask 中使用 pyecharts。
https://pyecharts.org/#/zh-cn/web_flask
def bar_base() -> Bar:
c = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [randrange(0, 100) for _ in range(6)])
.add_yaxis("商家B", [randrange(0, 100) for _ in range(6)])
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))
)
return c
def get_bar_chart():
c = bar_base()
return c.dump_options_with_quotes()
要转换的 dict
{
"backgroundColor": None,
"animation": True,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate ": 300,
"animationEasingUpdate ": "cubicOut ",
"animationDelayUpdate ": 0,
"color ": ["#c23531 ", "#2f4554", "# 61 a0a8 ", "#d48265 ",
"#749f83", "# ca8622 ", "#bda29a ",
"#6e7074", "# 546570 ", "#c4ccd3 ", "#f05b72 ",
"#ef5b9c ", "#f47920 ", "#905a3d", "# fab27b ", "#2a5caa", "# 444693 ", "#726930", "# b2d235 ",
"#6d8346", "# ac6767 ", "#1d953f",
"# 6950 a1 ",
"#918597"
],
"series": [{
"type": "pie",
"name": "商家",
"clockwise": True,
"data": [{
"name": "衬衫",
"value": 612
}, {
"name": "羊毛衫",
"value": 429
}, {
"name": "雪纺衫
", "
value ": 664}, {"
name ": "
裤子 ", "
value ": 734}, {"
name ": "
高跟鞋 ", "
value ": 980}, {"
name ": "
袜子 ", "
value ": 697}], "
radius ": ["
0 % ", "
75 % "], "
center ": ["
50 % ", "
50 % "], "
roseType ": None, "
label ": <pyecharts.options.series_options.LabelOpts object at 0x000000000D7E71C8>, "
tooltip ": None, "
itemStyle ": None, "
encode ": None}], "
legend ": [{"
d
ata ": ["
衬衫 ", "
羊毛衫 ", "
雪纺衫 ", "
裤子 ", "
高跟鞋 ", "
袜子 "], "
selected ": {}}], "
tooltip ": {"
show ": True, "
trigger ": "
item ", "
triggerOn ": "
mousemove | click ", "
axisPointer ": {"
type ": "
line "}, "
formatter ": None, "
textStyle ": <pyecharts.options.series_options.TextStyleOpts object at 0x000000000D75DBC8>, "
backgroundColor ": None, "
borderColor ": None, "
borderWidth ": 0}}
链式调用 是啥东东?
pyecharts 所有方法均支持链式调用。
from pyecharts.charts import Bar
bar = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
)
bar.render()
使用 options 配置项,在 pyecharts 中,一切皆 Options。
from pyecharts.charts import Bar
from pyecharts import options as opts
# V1 版本开始支持链式调用
# 你所看到的格式其实是 `black` 格式化以后的效果
# 可以执行 `pip install black` 下载使用
bar = (
Bar()
.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
# 或者直接使用字典参数
# .set_global_opts(title_opts={"text": "主标题", "subtext": "副标题"})
)
bar.render()
# 不习惯链式调用的开发者依旧可以单独调用方法
bar = Bar()
bar.add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"])
bar.add_yaxis("商家A", [5, 20, 36, 10, 75, 90])
bar.set_global_opts(title_opts=opts.TitleOpts(title="主标题", subtitle="副标题"))
bar.render()