main
HuangHai 4 months ago
parent 329d5cacd7
commit 693e2cf2fd

@ -138,35 +138,38 @@ async def get_column_names(db: asyncpg.Connection, sql: str):
return column_names
else:
return []
def generate_columns(data):
"""
根据数据生成 category_columns_str value_column_str
:param data: 数据集列表字典格式例如[{"行政区划": "北京", "学校": "清华附中", "课程数量": 100}, ...]
:param data: 数据集列表字典格式例如[{"行政区划": "二道区", "学校名称": "清华附中", "课程数量": 100}, ...]
:return: (category_columns_str, value_column_str)
"""
# 获取所有字段名
columns = list(data[0].keys()) if data else []
# 1. 有行政区划+学校两个字段的
if any("行政区划" in col for col in columns) and any("学校" in col for col in columns):
category_columns_str = "行政区划,学校"
# 1. 有行政区划名+学校名称两个字段的
if "行政区划名" in columns and "学校名称" in columns:
category_columns_str = "行政区划名,学校名称"
elif "行政区划" in columns and "学校名称" in columns:
category_columns_str = "行政区划,学校名称"
# 2. 有学段+科目的
elif any("学段" in col for col in columns) and any("科目" in col for col in columns):
elif "学段" in columns and "科目" in columns:
category_columns_str = "学段,科目"
# 3. 只有行政区
elif any("行政区划" in col for col in columns):
category_columns_str = "行政区划"
# 3. 只有行政区划名
elif "行政区划" in columns:
category_columns_str = "行政区划"
# 4. 只有学段的
elif any("学段" in col for col in columns):
elif "学段" in columns:
category_columns_str = "学段"
# 5. 上面都不是的,用第一个字段记录
else:
category_columns_str = columns[0] if columns else ""
# 6. Y轴一般的常见词是课程数量数量如果都没有用最后一个字段记录
if any("课程数量" in col for col in columns):
if "课程数量" in columns:
value_column_str = "课程数量"
elif any("数量" in col for col in columns):
elif "数量" in columns:
value_column_str = "数量"
else:
value_column_str = columns[-1] if columns else ""

@ -0,0 +1,500 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>长春云校数据统计分析系统</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
</head>
<body >
<style>.box { } </style>
<div class="box">
<div id="8adb5e23da53437691150745395ff43f" class="chart-container" style="width:900px; height:500px; "></div>
<script>
var chart_8adb5e23da53437691150745395ff43f = echarts.init(
document.getElementById('8adb5e23da53437691150745395ff43f'), 'white', {renderer: 'canvas'});
var option_8adb5e23da53437691150745395ff43f = {
"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": "\u8bfe\u7a0b\u6570\u91cf",
"legendHoverLink": true,
"data": [
422,
192,
120,
17,
10,
9,
7,
5,
4,
2,
228,
98,
36,
16,
6,
5,
4,
3,
2,
5
],
"realtimeSort": false,
"showBackground": false,
"stackStrategy": "samesign",
"cursor": "pointer",
"barWidth": "30%",
"barMinHeight": 0,
"barCategoryGap": "20%",
"barGap": "30%",
"large": false,
"largeThreshold": 400,
"seriesLayoutBy": "column",
"datasetIndex": 0,
"clip": true,
"zlevel": 0,
"z": 2,
"label": {
"show": true,
"margin": 8,
"valueAnimation": false
},
"itemStyle": {
"color": function(params) { var colorList = ['#5470C6', '#91CC75', '#EE6666', '#73C0DE', '#3BA272', '#FC8452', '#9A60B4', '#EA7CCC']; return colorList[params.dataIndex % colorList.length]; }
}
}
],
"legend": [
{
"data": [
"\u8bfe\u7a0b\u6570\u91cf"
],
"selected": {},
"show": false,
"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": [
{
"name": "\u884c\u653f\u533a\u5212\u540d - \u5b66\u6821\u540d\u79f0",
"show": true,
"scale": false,
"nameLocation": "end",
"nameGap": 15,
"gridIndex": 0,
"axisLabel": {
"show": true,
"rotate": 45,
"margin": 8,
"valueAnimation": false
},
"inverse": false,
"offset": 0,
"splitNumber": 5,
"boundaryGap": true,
"minInterval": 0,
"splitLine": {
"show": false,
"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": [
"\u4e8c\u9053\u533a - \u957f\u6625\u4e94\u5341\u4e8c\u4e2d\u8d6b\u884c\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u521d\u7ea7\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e00\u3007\u516b\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e8c\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e03\u4e2d\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u516b\u5341\u4e8c\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u82f1\u4fca\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u56fd\u9645\u7269\u6d41\u7ecf\u6d4e\u5f00\u53d1\u533a\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e09\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u4e94\u5341\u4e8c\u4e2d\u8d6b\u884c\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e00\u3007\u516b\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u56fd\u9645\u7269\u6d41\u7ecf\u6d4e\u5f00\u53d1\u533a\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u6559\u5e08\u8fdb\u4fee\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u4e1c\u76db\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e8c\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u8fdc\u8fbe\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u521d\u7ea7\u4e2d\u5b66"
]
}
],
"yAxis": [
{
"name": "\u8bfe\u7a0b\u6570\u91cf",
"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": "\u957f\u6625\u4e91\u6821\u8bfe\u7a0b\u5efa\u8bbe\u7edf\u8ba1\u56fe",
"target": "blank",
"subtarget": "blank",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
]
};
chart_8adb5e23da53437691150745395ff43f.setOption(option_8adb5e23da53437691150745395ff43f);
</script>
<br/> <div id="f755bbad2cda40ac9cda2bf4607edf11" class="chart-container" style="width:900px; height:500px; "></div>
<script>
var chart_f755bbad2cda40ac9cda2bf4607edf11 = echarts.init(
document.getElementById('f755bbad2cda40ac9cda2bf4607edf11'), 'white', {renderer: 'canvas'});
var option_f755bbad2cda40ac9cda2bf4607edf11 = {
"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": "pie",
"name": "\u5360\u6bd4",
"colorBy": "data",
"legendHoverLink": true,
"selectedMode": false,
"selectedOffset": 10,
"clockwise": true,
"startAngle": 90,
"minAngle": 0,
"minShowLabelAngle": 0,
"avoidLabelOverlap": true,
"stillShowZeroSum": true,
"percentPrecision": 2,
"showEmptyCircle": true,
"emptyCircleStyle": {
"color": "lightgray",
"borderColor": "#000",
"borderWidth": 0,
"borderType": "solid",
"borderDashOffset": 0,
"borderCap": "butt",
"borderJoin": "bevel",
"borderMiterLimit": 10,
"opacity": 1
},
"data": [
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u4e94\u5341\u4e8c\u4e2d\u8d6b\u884c\u5b9e\u9a8c\u5b66\u6821",
"value": 422
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u521d\u7ea7\u4e2d\u5b66",
"value": 192
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e00\u3007\u516b\u5b66\u6821",
"value": 120
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e8c\u4e2d\u5b66",
"value": 17
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e03\u4e2d\u5b66\u6821",
"value": 10
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u516b\u5341\u4e8c\u4e2d\u5b66",
"value": 9
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u82f1\u4fca\u4e2d\u5b66",
"value": 7
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u56fd\u9645\u7269\u6d41\u7ecf\u6d4e\u5f00\u53d1\u533a\u5b9e\u9a8c\u5b66\u6821",
"value": 5
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u4e2d\u5b66",
"value": 4
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e09\u4e2d\u5b66",
"value": 2
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u5c0f\u5b66",
"value": 228
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u4e94\u5341\u4e8c\u4e2d\u8d6b\u884c\u5b9e\u9a8c\u5b66\u6821",
"value": 98
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e00\u3007\u516b\u5b66\u6821",
"value": 36
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u56fd\u9645\u7269\u6d41\u7ecf\u6d4e\u5f00\u53d1\u533a\u5b9e\u9a8c\u5b66\u6821",
"value": 16
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u6559\u5e08\u8fdb\u4fee\u5b66\u6821",
"value": 6
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u4e1c\u76db\u5c0f\u5b66",
"value": 5
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e8c\u4e2d\u5b66",
"value": 4
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u8fdc\u8fbe\u5c0f\u5b66",
"value": 3
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u5c0f\u5b66",
"value": 2
},
{
"name": "\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u521d\u7ea7\u4e2d\u5b66",
"value": 5
}
],
"radius": [
"30%",
"55%"
],
"center": [
"50%",
"50%"
],
"label": {
"show": true,
"position": "outside",
"margin": 8,
"fontSize": 14,
"formatter": "{b}\n{d}%",
"valueAnimation": false
},
"labelLine": {
"show": true,
"showAbove": false,
"length": 15,
"length2": 15,
"smooth": false,
"minTurnAngle": 90,
"maxSurfaceAngle": 90
},
"itemStyle": {
"color": function(params) { var colorList = ['#5470C6', '#91CC75', '#EE6666', '#73C0DE', '#3BA272', '#FC8452', '#9A60B4', '#EA7CCC']; return colorList[params.dataIndex % colorList.length]; }
}
}
],
"legend": [
{
"data": [
"\u4e8c\u9053\u533a - \u957f\u6625\u4e94\u5341\u4e8c\u4e2d\u8d6b\u884c\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u521d\u7ea7\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e00\u3007\u516b\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e8c\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e03\u4e2d\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u516b\u5341\u4e8c\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u82f1\u4fca\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u56fd\u9645\u7269\u6d41\u7ecf\u6d4e\u5f00\u53d1\u533a\u5b9e\u9a8c\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u7b2c\u4e94\u5341\u4e09\u4e2d\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u529b\u65fa\u5b9e\u9a8c\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u6559\u5e08\u8fdb\u4fee\u5b66\u6821",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u4e1c\u76db\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u8fdc\u8fbe\u5c0f\u5b66",
"\u4e8c\u9053\u533a - \u957f\u6625\u5e02\u4e8c\u9053\u533a\u516c\u5e73\u5c0f\u5b66"
],
"selected": {},
"show": false,
"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"
},
"title": [
{
"show": true,
"text": "\u957f\u6625\u4e91\u6821\u8bfe\u7a0b\u5efa\u8bbe\u7edf\u8ba1\u56fe",
"target": "blank",
"subtext": "\u6570\u636e\u7ef4\u5ea6\uff1a\u884c\u653f\u533a\u5212\u540d \u2192 \u5b66\u6821\u540d\u79f0",
"subtarget": "blank",
"padding": 5,
"itemGap": 10,
"textAlign": "auto",
"textVerticalAlign": "auto",
"triggerEvent": false
}
]
};
chart_f755bbad2cda40ac9cda2bf4607edf11.setOption(option_f755bbad2cda40ac9cda2bf4607edf11);
</script>
<br/> </div>
<script>
</script>
</body>
</html>
Loading…
Cancel
Save