Toggle navigation
自定义系列:柱形图顶点加折线
By
A***9
2019-03-12 06:27:26
脚本
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 colors = ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'] var yearCount = 7; var categoryCount = 30; var xAxisData = []; // var customData = []; var legendData = []; var dataList = []; legendData.push('trend'); var encodeY = []; for (var i = 0; i < yearCount; i++) { legendData.push((2010 + i) + ''); dataList.push([]); // customData.push([i]) encodeY.push(1 + i); } for (var i = 0; i < categoryCount; i++) { var val = Math.random() * 1000; xAxisData.push('category' + i); var data = dataList[0]; for (var j = 0; j < dataList.length; j++) { var value = j === 0 ? echarts.number.round(val, 2) : echarts.number.round(Math.max(0, dataList[j - 1][i] + (Math.random() - 0.5) * 200), 2); dataList[j].push(value); // customData[j].push(value); } } // console.log(dataList) function renderItem(params, api) { //renderItem针对当前data的每个应该显示(由dataZoom控制)的dataItem项执行,data.length需要等于category长度 var xValue = api.value(0);//api.value(x)表示dataItem[x]或者dataIndex,0通常用来存放dataIndex便于识别数据 var xStartValue = params.dataIndex - params.dataIndexInside ; var xEndValue = params.dataIndex - params.dataIndexInside + params.dataInsideLength ; var currentSeriesIndices = api.currentSeriesIndices();//得到系列的 当前index组。注意这个 index 不同于系列定义时的 index。这个 index 是当 legend 组件进行了系列筛选后,剩余的系列排列后的 index。 var barLayout = api.barLayout({ barGap: '30%', barCategoryGap: '20%', count: currentSeriesIndices.length - 1 }); // console.log(params); // console.log(xValue); var pointsList = []; if (params.dataIndexInside === 0){//当当前renderItem是第一个渲染的时候,才绘制自定义图形 // console.log(xStartValue,xEndValue) for (var i = 0; i < currentSeriesIndices.length; i++) { var seriesIndex = currentSeriesIndices[i];//遍历当前Legend筛选后的index组 if (seriesIndex !== params.seriesIndex) { var points = []; for (var j = xStartValue;j < xEndValue;j++){ var point = api.coord([j, dataList[seriesIndex-1][j]]); point[0] += barLayout[i - 1].offsetCenter; point[1] -= 0; points.push(point); } pointsList.push(points) } } return { type:'group', children:echarts.util.map(pointsList, function (points, index) { return { type: 'polyline', animation: true, name: 'Year' + (index), shape: { points: points }, style: api.style({ stroke: colors[currentSeriesIndices[index]],//api.visual('color'), fill: null }) }; }) }; } // var style = api.style({ // stroke: api.visual('color'), // fill: null // }); // console.log(pointsList) } option = { tooltip: { trigger: 'axis' }, legend: { data: legendData }, dataZoom: [{ type: 'slider', start: 50, end: 70 }, { type: 'inside', start: 50, end: 70 }], xAxis: { data: xAxisData }, yAxis: {}, series: [{ type: 'custom', name: 'trend', renderItem: renderItem, itemStyle: { normal: { borderWidth: 2 } }, // encode: { // x: 0, // y: encodeY // }, data: dataList[0], z: 100 }].concat(echarts.util.map(dataList, function (data, index) { return { type: 'bar', animation: false, name: legendData[index + 1], itemStyle: { normal: { opacity: 0.5, color:colors[index] } }, data: data }; })) };; if (option && typeof option === "object") { myChart.setOption(option, true); };