echarts 曲线中显示最大值进行标签样式的设置和修改
曲线中最大值最小值需要完善一些相关的信息
let color = [ '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
let xData =['00:00', '04:00', '08:00', '12:00', '16:00', '20:00', '24:00']
//item 是循环的后台返回的数据,用来构造有几条曲线
//关键代码还是markPoint中的内容
data.series.forEach((item,index) => {
let lineColor = color[index]
series.push({ name: item.name, type: 'line', lineStyle: { color: lineColor, // 折线颜色 }, itemStyle: { color: lineColor // 这里设置图例的颜色 }, data: item.data, markPoint: { data: [{ type: 'max', name: '最大值' }, ], //symbol: 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIwAAAA+CAYAAAD5wvNAAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA0xpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMDY3IDc5LjE1Nzc0NywgMjAxNS8wMy8zMC0yMzo0MDo0MiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjQ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,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z', symbolSize: [1, 1], // 容器大小 symbolOffset: [0, -15], //位置偏移 // 显示标签: itemStyle: { normal: { label: { show: true, formatter: function(params) { //格式化展现(标签+值) let indexData = params.data.coord[0]
//这个params中可以获取到当前的indexData 即当前的最大值的index位置,可以拿到数组中当前index中的 x轴的数据 let xdata =xData [indexData] return params.name + ':' + params.value+"\n"+'时间:'+xdata }, // borderColor:'yellow', lineHeight: 18, padding:[0, 5, 0, 5], borderRadius:[6,6,6,6], backgroundColor:'rgb(216,216,216,0.6)', color:lineColor }, //color:'#fff', } } }, }) })