'commit'
This commit is contained in:
39
Test/TestEcharts.py
Normal file
39
Test/TestEcharts.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# pip install pyecharts
|
||||
import pyecharts
|
||||
import json
|
||||
|
||||
#print(pyecharts.__version__)
|
||||
from pyecharts import options as opts
|
||||
from pyecharts.charts import Bar
|
||||
from pyecharts.faker import Faker
|
||||
from pyecharts.globals import CurrentConfig
|
||||
|
||||
# 配置使用自定义的 ECharts 路径
|
||||
CurrentConfig.ONLINE_HOST = "https://gcore.jsdelivr.net/npm/echarts@6.0.0/dist/"
|
||||
|
||||
c = (
|
||||
Bar()
|
||||
.add_xaxis(Faker.choose())
|
||||
.add_yaxis("商家A", Faker.values())
|
||||
.add_yaxis("商家B", Faker.values())
|
||||
.set_global_opts(title_opts=opts.TitleOpts(title="Bar-MarkLine(自定义)"))
|
||||
.set_series_opts(
|
||||
label_opts=opts.LabelOpts(is_show=False),
|
||||
markline_opts=opts.MarkLineOpts(
|
||||
data=[opts.MarkLineItem(y=50, name="yAxis=50")]
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
# 获取图表的选项配置
|
||||
options = c.get_options()
|
||||
|
||||
# 将选项转换为 JSON 字符串
|
||||
json_str = json.dumps(options, indent=2, ensure_ascii=False)
|
||||
|
||||
# 输出 JSON 字符串
|
||||
print(json_str)
|
||||
|
||||
# 可选:将 JSON 保存到文件
|
||||
with open("bar_chart_config.json", "w", encoding="utf-8") as f:
|
||||
f.write(json_str).render("bar_markline_custom.html"))
|
Reference in New Issue
Block a user