Toggle navigation
象形柱图
By
b***n
2019-11-28 09:56:12
脚本
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 chartData = [ {value: 0.7, name:'惠南'}, {value: 0.9, name:'三林'}, {value: 0.2, name:'张江'}, {value: 0.5, name:'高东'}, {value: 0.8, name:'高行'}, {value: 0.7, name:'金桥'}, {value: 0.9, name:'曹路'}, {value: 0.2, name:'唐镇'}, {value: 0.5, name:'合庆'}, {value: 0.8, name:'北蔡'}, {value: 0.7, name:'高桥'}, {value: 0.9, name:'川沙'}, {value: 0.2, name:'花木'}, {value: 0.5, name:'东明'}, {value: 0.8, name:'浦兴'} ]; var itemData = [], bgData = []; // 取出每一条数据value,作为显示数据 chartData.forEach(function(items, index) { itemData.push(items.value); }); // 取出所有数据最大值,作为背景象形柱图数据 chartData.forEach(function(items, index) { bgData.push(Math.max.apply(null, itemData)); }); var sum = eval(itemData.join("+")); //eval方法求和公式 console.log("dataValue求和值为:"+sum); var averageValue = Math.abs((sum / itemData.length * 100) / 100).toFixed(1); //求平均值 console.log("dataValue求平均值为:"+"%c"+averageValue, "color:red"); option = { backgroundColor: '#000e46', title : { show:false }, tooltip : {//提示框(悬浮框) trigger: 'axis', backgroundColor:'rgba(0,0,0,0.7)', borderRadius:2, axisPointer: { type: "shadow" }, textStyle: { color: "#fff", fontSize: 14 }, formatter: "{a}
{b}: {c}" }, legend: { show: false }, grid: { x:40, y:60, x2:30, y2:60, }, xAxis : [ { type: 'category',//种类是类目 axisLine:{ lineStyle:{ color:'#181970', width:1 } }, axisTick:{ show:false, //坐标轴小标记 inside:false, //小标记是否显示为在grid内部,默认在外部 lineStyle: { color: '#3f5a8c', //小标记颜色 width:2 } }, axisLabel: {//坐标轴标签 show: true, textStyle: { color: '#ffffff', fontSize: 16 }, /*formatter: '{value}'*/ formatter:function(value){ return value.split("").join("\n"); } }, data: (function(data){ var arr=[]; data.forEach(function(items){ arr.push(items.name); }); return arr; })(chartData) //x轴data } ],//x轴 yAxis : [ { min: 0, max: 1.0, interval: 0.2, axisTick:{ show:false, //坐标轴小标记 inside:false, //小标记是否显示为在grid内部,默认在外部 lineStyle: { color: '#3f5a8c', //小标记颜色 width:2 } },//坐标轴刻度 axisLine:{ show:false, },//坐标轴线 splitLine:{ show: false, lineStyle:{ color:'#181970', width:1 } },//轴向网格线 axisLabel: { show: true, textStyle: { color: '#ffffff', fontSize: 16 }, formatter: '{value}' } //坐标轴标签 } ],//y轴 animationEasing: 'elasticOut', series: [{ name: '检查覆盖率', type: 'pictorialBar', //象形柱图 symbol: 'rect', symbolRepeat: true, symbolSize:[16, 4], symbolMargin: 2, //图形的两边间隔 itemStyle: { normal:{ //color:"#fec85f" color: function(params){ // 颜色定制显示(按顺序)console.log(params) var colorList= []; for(var i=0; i< chartData.length; i++){ if(params.value > averageValue){ colorList.push('#5878ff'); }else{ colorList.push('#ef9356'); }//console.log(colorList); return colorList; } return colorList[params.dataIndex]; } }, }, markLine: { precision: 1, //标线数值的精度,在显示平均值线的时候有用(即小数点后第几位) data : [ {type : 'average', name: '平均值'} ], lineStyle: { normal: { type: 'dashed', color: '#ef4034', width: 2, }, }, label:{ show: true, formatter:function(params){ //强制设置平均值 var res = averageValue return res; } } }, data: itemData //数据 }, { name: '', type: 'pictorialBar', symbol: 'rect', symbolRepeat: true, symbolSize:[16, 4], symbolMargin: 2, color:'#272762', barGap : '-100%', z: 1, data: bgData //背景数据 }] };