Toggle navigation
各城市占比
By
walle_zhang
2018-04-18 07:05:29
脚本
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 baifenbi = [0.111, 0.333, 0.444, 0.222, 0.333, 0.333, 0.46]; const bgBar = [1, 1, 1, 1, 1, 1, 1]; const _baifenbi = []; const colors = ['#11D0A8', '#FF9F01', '#781414', '#03A6AB', '#E8B47B', '#F54323', '#D011C9'] const city = ['北京', '上海', '西安', '广州', '深圳', '重庆', '武汉']; const richs = {}; //定义富文本样式,为了匹配label字体的样式 city.forEach((ele, i) => { let a = 'a' + i richs[a] = { color: colors[i], fontSize: 15, } }) console.log(richs) baifenbi.forEach((ele, i) => { _baifenbi.push({ name: city[i], value: ele, itemStyle: { normal: { color: colors[i] } } }) }) option = { title: { text: '各城市占比', left: 'left', top: '0%', textStyle: { fontSize: 20, } }, grid: { left: '2%', bottom: '2%', right: '5%', top: '7%', }, xAxis: { show: false, }, yAxis: { type: 'category', axisLabel: { show: false, //让Y轴数据不显示 }, itemStyle: { }, axisTick: { show: false, //隐藏Y轴刻度 }, axisLine: { show: false, //隐藏Y轴线段 }, data: city, }, series: [ //背景色--------------------我是分割线君------------------------------// { show: true, type: 'bar', barGap: '-100%', //两列柱子都设置成-100%可以保证他们重合 barCategoryGap: '50%', barWidth: 30, //统计条宽度 itemStyle: { normal: { color: 'rgba(14, 26, 36,1)' }, }, z: 1, data: bgBar, label: { normal: { show: true, position: 'insideRight', //这种用HTML样式的方法不行 // formatter: function(data) { // // console.log("bg",data) // // console.log(option.series[1].data) // const series1 = option.series[1].data; // let str = "" // series1.forEach(ele => { // if(ele.name===data.name){ // const aa = '#d011c9' // str+='
' // // str+="
" // str+= data.name+' '+(baifenbi[data.dataIndex] * 100).toFixed(1) + '%'; // } // }); // str+="
" // console.log(str) // return str; // // return data.name+' '+(baifenbi[data.dataIndex] * 100).toFixed(1) + '%' // }, //为了让label用背景色去定位,且label字体颜色必须和柱子颜色一样 formatter: function(data) { const series1 = option.series[1].data; let str = "" series1.forEach((ele, i) => { if (ele.name === data.name) { let aa = "a" + i str += '{' + aa + '| ' + data.name + ' ' + (baifenbi[data.dataIndex] * 100).toFixed(1) + '%' + '}'; } }); return str; }, rich: richs } }, }, //蓝条--------------------我是分割线君------------------------------// { show: true, type: 'bar', barGap: '-100%', barCategoryGap: '50%', barWidth: 30, //统计条宽度 max: 1, labelLine: { show: false, }, z: 2, data: _baifenbi, }, ] }