diff --git a/Test/TestEcharts.py b/Test/TestEcharts.py new file mode 100644 index 0000000..0beca7d --- /dev/null +++ b/Test/TestEcharts.py @@ -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")) diff --git a/Test/__init__.py b/Test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Test/bar_markline_custom.html b/Test/bar_markline_custom.html new file mode 100644 index 0000000..8e2dfeb --- /dev/null +++ b/Test/bar_markline_custom.html @@ -0,0 +1,286 @@ + + +
+ +