This commit is contained in:
2025-09-10 15:01:32 +08:00
parent 72427e9e43
commit 68bc79452f
4 changed files with 325 additions and 0 deletions

39
Test/TestEcharts.py Normal file
View 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"))