echarts4组柱状图颜色按小值排最前面大值排最后面

阅读: 评论:0

echarts4组柱状图颜色按小值排最前面大值排最后面

echarts4组柱状图颜色按小值排最前面大值排最后面

// 从大到小排序sortList(arr) {return arr.sort((a, b) => {return b.value - a.value})},initBar() {// 数据处理const aList = [5, 25, 13, 5]const bList = [10, 20, 49, 15]const cList = [15, 10, 23, 35]const dList = [25, 7, 18, 33]const aBar = []const bBar = []const cBar = []const dBar = []for (let i=0; i < aList.length; i++) {const tempArr = [{value: aList[i],color: 'blue'},{value: bList[i],color: 'green'},{value: cList[i],color: 'red'},{value: dList[i],color: 'orange'}]const sortedArr = this.sortList(tempArr)aBar.push({value: sortedArr[0].value,type: 'blue',itemStyle: {color: sortedArr[0].color}})bBar.push({value: sortedArr[1].value,type: 'green',itemStyle: {color: sortedArr[1].color}})cBar.push({value: sortedArr[2].value,type: 'red',itemStyle: {color: sortedArr[2].color}})dBar.push({value: sortedArr[3].value,type: 'orange',itemStyle: {color: sortedArr[3].color}})}var chartDom = ElementById('pieChart');var myChart = echarts.init(chartDom);var option;option = {xAxis: {data: ['a', 'b', 'c', 'd'],axisTick: {show: false},axisLabel: {formatter: 'barGap: '-100%''}},yAxis: {splitLine: {show: false}},animationDurationUpdate: 1200,series: [{type: 'bar',itemStyle: {normal: {color: '#ddd'}},silent: false,barWidth: 40,barGap: '-100%', // Make series be overlapdata: [60, 60, 60, 60]}, {type: 'bar',barWidth: 40,z: 10,data: aBar}, {type: 'bar',barWidth: 40,z: 11,data: bBar}, {type: 'bar',barWidth: 40,z: 12,data: cBar}, {type: 'bar',barWidth: 40,z: 13,data: dBar}]};option && myChart.setOption(option);('click', function (param) {  //param参数包含的内容有: //param.name:X轴的值 //param.data:Y轴的值 //param.value:Y轴的值 //pe:点击事件均为click //param.seriesName:legend的名称 //param.seriesIndex:系列序号(series中当前图形是第几个图形第几个) //param.dataIndex:数值序列(X轴上当前点是第几个点)//alert(param.seriesName);  //legend的名称// console.log(param);  //X轴的值console.log(option.series[param.seriesIndex].data[param.dataIndex]);//获取自定义的值});}

本文发布于:2024-01-28 22:34:24,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170645246710771.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23