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"))

0
Test/__init__.py Normal file
View File

View File

@@ -0,0 +1,286 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Awesome-pyecharts</title>
<script type="text/javascript" src="https://gcore.jsdelivr.net/npm/echarts@6.0.0/dist/echarts.min.js"></script>
</head>
<body >
<div id="c0285272d60b4a42ae1f1408018c9af0" class="chart-container" style="width:900px; height:500px; "></div>
<script>
var chart_c0285272d60b4a42ae1f1408018c9af0 = echarts.init(
document.getElementById('c0285272d60b4a42ae1f1408018c9af0'), 'white', {renderer: 'canvas'});
var option_c0285272d60b4a42ae1f1408018c9af0 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"aria": {
"enabled": false
},
"color": [
"#5470c6",
"#91cc75",
"#fac858",
"#ee6666",
"#73c0de",
"#3ba272",
"#fc8452",
"#9a60b4",
"#ea7ccc"
],
"series": [
{
"type": "bar",
"name": "\u5546\u5bb6A",
"legendHoverLink": true,
"data": [
122,
108,
81,
140,
29,
44,
123
],
"realtimeSort": false,
"showBackground": false,
"stackStrategy": "samesign",
"cursor": "pointer",
"barMinHeight": 0,
"barCategoryGap": "20%",
"barGap": "30%",
"large": false,
"largeThreshold": 400,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"clip": true,
"zlevel": 0,
"z": 2,
"label": {
"show": false,
"margin": 8,
"valueAnimation": false
},
"markLine": {
"silent": false,
"precision": 2,
"label": {
"show": true,
"margin": 8,
"valueAnimation": false
},
"data": [
{
"name": "yAxis=50",
"yAxis": 50
}
]
},
"rippleEffect": {
"show": true,
"brushType": "stroke",
"scale": 2.5,
"period": 4
}
},
{
"type": "bar",
"name": "\u5546\u5bb6B",
"legendHoverLink": true,
"data": [
115,
50,
20,
27,
117,
86,
136
],
"realtimeSort": false,
"showBackground": false,
"stackStrategy": "samesign",
"cursor": "pointer",
"barMinHeight": 0,
"barCategoryGap": "20%",
"barGap": "30%",
"large": false,
"largeThreshold": 400,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"clip": true,
"zlevel": 0,
"z": 2,
"label": {
"show": false,
"margin": 8,
"valueAnimation": false
},
"markLine": {
"silent": false,
"precision": 2,
"label": {
"show": true,
"margin": 8,
"valueAnimation": false
},
"data": [
{
"name": "yAxis=50",
"yAxis": 50
}
]
},
"rippleEffect": {
"show": true,
"brushType": "stroke",
"scale": 2.5,
"period": 4
}
}
],
"legend": [
{
"data": [
"\u5546\u5bb6A",
"\u5546\u5bb6B"
],
"selected": {},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14,
"backgroundColor": "transparent",
"borderColor": "#ccc",
"borderRadius": 0,
"pageButtonItemGap": 5,
"pageButtonPosition": "end",
"pageFormatter": "{current}/{total}",
"pageIconColor": "#2f4554",
"pageIconInactiveColor": "#aaa",
"pageIconSize": 15,
"animationDurationUpdate": 800,
"selector": false,
"selectorPosition": "auto",
"selectorItemGap": 7,
"selectorButtonGap": 10
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"enterable": false,
"confine": false,
"appendToBody": false,
"transitionDuration": 0.4,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5,
"order": "seriesAsc"
},
"xAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"data": [
"\u5c0f\u7c73",
"\u4e09\u661f",
"\u534e\u4e3a",
"\u82f9\u679c",
"\u9b45\u65cf",
"VIVO",
"OPPO"
]
}
],
"yAxis": [
{
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"inverse": false,
"offset": 0,
"splitNumber": 5,
"minInterval": 0,
"splitLine": {
"show": true,
"lineStyle": {
"show": true,
"width": 1,
"opacity": 1,
"curveness": 0,
"type": "solid"
}
},
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0
}
],
"title": [
{
"show": true,
"text": "Bar-MarkLine\uff08\u81ea\u5b9a\u4e49\uff09",
"target": "blank",
"subtarget": "blank",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
]
};
chart_c0285272d60b4a42ae1f1408018c9af0.setOption(option_c0285272d60b4a42ae1f1408018c9af0);
</script>
</body>
</html>