// 从大到小排序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 条评论) |