Toggle navigation
堆叠柱状图显示总数
By
最***字
2020-11-05 11:51:49
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
var data = [{ "city": "地区一", "so2": 12, "o3": 21, "num": 33 }, { "city": "地区二", "so2": 10, "o3": 25, "num": 35 }, { "city": "地区三", "so2": 20, "o3": 25, "num": 45 }, { "city": "地区四", "so2": 30, "o3": 25, "num": 55 } ]; var aNum = [], aSO2 = [], aO3 = [], aIndicator = []; var i, nLen = data.length, oItem; for (i = 0; i < nLen; i++) { oItem = data[i]; aNum.push(oItem.num); aSO2.push(oItem.so2); aO3.push(oItem.o3); aIndicator.push(oItem.city); } // 修改图例角标 function replaceWords(str) { return str.replace("SO2", "SO{sub|2}") .replace("O3", "O{sub|3}"); } option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return data[params[0].dataIndex].city + '
' + '
' + 'SO2:' + data[params[0].dataIndex].so2 + '
' + '
' + 'O3:' + data[params[0].dataIndex].o3 } }, legend: { show: true, right: 20, data: [{ name: "SO2", icon: 'rect' }, { name: "O3", icon: 'rect' }, ], // 使用自定义方法处理图例 formatter: function(name) { return replaceWords(name); }, textStyle: { lineHeight: 12, verticalAlign: "middle", fontSize: 12, rich: { // 数字下标 sub: { verticalAlign: "bottom", fontSize: 8 }, } } }, grid: { top: '10%', left: '10%', right: '10%', bottom: '10%', containLabel: true }, xAxis: { type: 'value', axisLine: { show: true, lineStyle: { color: '#686868' } }, axisLabel: { show: true, color: '#686868', fontSize: 16 }, axisTick: { show: false }, splitLine: { show: true, lineStyle: { color: '#D5D5D6' } } }, yAxis: { type: 'category', data: aIndicator, inverse: true, //反向坐标轴 axisLine: { show: false }, axisLabel: { show: true, color: '#686868', fontSize: 16 }, axisTick: { show: false }, splitLine: { show: false } }, series: [{ name: 'SO2', type: 'bar', barWidth: 20, stack: '因子', data: aSO2, itemStyle: { color: '#FFD237', shadowColor: 'rgba(0, 0, 0, 0.16)', shadowOffsetX: 0, shadowOffsetY: 3, shadowBlur: 6 } }, { name: 'O3', type: 'bar', barWidth: 20, stack: '因子', data: aO3, itemStyle: { color: '#F39927', shadowColor: 'rgba(0, 0, 0, 0.16)', shadowOffsetX: 0, shadowOffsetY: 3, shadowBlur: 6 } }, { name: '总计', type: 'bar', barWidth: 20, barGap: '-100%', // 移动使两根柱子重叠 label: { show: true, offset: [10, 0], position: 'right', textStyle: { color: '#686868', fontSize: 16 } }, itemStyle: { normal: { color: 'transparent' // 设置背景颜色为透明 } }, data: aNum } ] }