Toggle navigation
柱形占比图
By
漱***0
2020-11-30 14:48:19
脚本
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
图表已生成
整理代码
刷新
代码
const track = true; //是否有轨道 const topColor = '#00B8FF'; //排名前三的柱形颜色: { const lastColor = '#40E9B1'; //排名后面的柱形颜色: { const valueSuffix = '万'; //名称后缀 const names = [ '年收入第1名', '年收入第2名', '年收入第3名', '年收入第4名', '年收入第5名', '年收入第6名', '年收入第7名', '年收入第8名', '年收入第9名', '年收入第10名', ]; const values = [7500, 7000, 6500, 6000, 5500, 5000, 4500, 4000, 3500, 3000]; let lineY = []; let lineT = []; for (let i = 0; i < names.length; i++) { const data = { name: names[i], value: values[i], barGap: '-100%', itemStyle: { show: true, color: i < 3 ? topColor : lastColor, barBorderRadius: 5, }, }; lineY.push(data); //有轨道 if (track) { const data1 = { value: values[0], realValue: values[i], itemStyle: { color: '#2B3B6D', barBorderRadius: 10, }, }; lineT.push(data1); } } option = { backgroundColor: '#FFF', tooltip: { trigger: 'item', formatter: (p) => { if (p.seriesName === 'total') { return ''; } return `${p.name}
${p.value}万`; }, }, grid: { borderWidth: 0, top: '10%', left: '10%', right: '10%', bottom: '10%', }, yAxis: [{ type: 'category', show: false, inverse: true, axisLine: { show: false }, axisTick: { show: false }, axisLabel: { show: true, inside: false, verticalAlign: 'bottom', lineHeight: '40', textStyle: { color: '#b3ccf8', fontSize: '14', fontFamily: 'PingFangSC-Regular', }, formatter: function(val) { return `${val}ee`; }, }, splitArea: { show: false, }, splitLine: { show: false, }, data: values, }, ], xAxis: { type: 'value', show: false, axisTick: { show: false }, axisLine: { show: false }, splitLine: { show: false }, axisLabel: { show: false }, }, series: [], }; //带名称的公用配置 const nameBar = { name: 'bar', type: 'bar', zlevel: 1, barWidth: '6px', data: lineY, barGap: '-100%', label: { color: '#b3ccf8', show: true, position: [0, '-18px'], formatter: function(a) { let str = ''; str = a.name; return str; }, rich: { color: { color: '#949FD5', fontSize: 12, }, }, }, }; //有轨道 if (track) { option.series = [ nameBar, { name: 'total', type: 'bar', zlevel: -1, barGap: '-100%', barWidth: '6px', data: lineT, legendHoverLink: false, label: { show: true, position: 'right', formatter: (a) => { let str = ''; if (a.dataIndex < 3) { str = `{top|${a.data.realValue}${ valueSuffix || ''}}{unit|${valueSuffix?'':'万'}}`; } else { str = `{last|${a.data.realValue}${valueSuffix || ''}}{unit|${valueSuffix?'':'万'}}`; } return str; }, rich: { top: { fontSize: 14, color: topColor, }, last: { fontSize: 14, color: lastColor, }, unit: { color: '#949FD5', fontSize: 11, }, }, }, }, ]; } else { //无轨道 option.series = [ nameBar, { name: 'bar', type: 'bar', zlevel: 2, barWidth: '6px', data: lineY, label: { show: true, position: 'right', textStyle: { fontSize: 14, }, formatter: function(a) { let str = ''; str = `${a.value}{unit|万}`; return str; }, rich: { unit: { color: '#949FD5', fontSize: 11, }, }, }, }, ]; }