Toggle navigation
不使用visualMap实现折线图的分段显示
By
s***3
2019-05-13 07:11:01
脚本
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 color1 = ['#00B0F0', '#2e4f48']; var seriesData = [0, 1, 3, 10, 21, 27, 29]; var xAxisData = ['航班1', '航班2', '航班3', '航班4', '航班5', '航班6', '航班7']; option = { backgroundColor: '#272b2b', color: color1, textStyle: { fontSize: 16 }, title: { text: '使用线条渐变实现折线图分段显示', left: 'center', top: '3%', textStyle: { color: '#fff', fontSize: 20 } }, legend: { show: true, orient: 'vertical', top: '9%', left: 'center', /*itemWidth: 15, itemHeight: 15, itemGap: 20,*/ textStyle: { color: '#fff', fontSize: 14 }, data: ['自动'] }, xAxis: { type: 'category', data: [], axisLabel: { show: true, interval: 0, align: 'right', textStyle: { color: '#fff', fontSize: 16 } }, axisLine: { lineStyle: { color: '#fff' } }, axisTick: { inside: true } }, yAxis: { type: 'value', name: '累积延误(分钟)', axisLabel: { show: true, textStyle: { color: '#fff', fontSize: 14 } }, axisLine: { lineStyle: { color: '#fff' } }, axisTick: { inside: true }, splitArea: { show: false }, splitLine: { show: false } }, grid: { left: '45px', right: '5%', top: '15%', bottom: '5%', containLabel: true }, series: [{ name: '自动', data: [], type: 'line', smooth: false, lineStyle: { shadowBlur: 10, shadowColor: color1[0] }, markLine: { symbol: 'circle', label: { normal: { position: 'middle', formatter: function(e) { var name = e.name; if (name !== '' && e.dataIndex == 2) { name = name; } return name; } } }, data: [] }, markPoint: { symbolSize: 30, itemStyle: { color: '#FF0000' } } }] }; var xAxisDatax = []; var textStyle = {}; $.each(xAxisData, function(i, val) { if (i == 5) { textStyle = { borderColor: '#00B0F0', borderWidth: 1, padding: 6 }; } else if (i == 6) { textStyle = { borderColor: '#FF0000', borderWidth: 1, padding: 6 }; } else { textStyle = { padding: 6 }; } xAxisDatax.push({ value: val, textStyle: textStyle }); }); // 计算最大拐点、最后一个受影响航班、后续航班 var maxPoint = [3, 4]; // 最大拐点段的开始及结束值(第一个点不算) var totalPoint = xAxisData.length - 1; // 拐点个数(需减1) var lastPointIndex = xAxisData.length - 2; var nextPointIndex = xAxisData.length - 1; // 获取最大数值 var maxValue = 35; // 标线设置 option.series[0].markLine.data = [ [{ coord: [lastPointIndex, 0], valueIndex: 0, lineStyle: { color: color1[0] } }, { coord: [lastPointIndex, seriesData[lastPointIndex]], valueIndex: 0 } ], [{ coord: [nextPointIndex, 0], valueIndex: 0, lineStyle: { color: '#FF0000' } }, { coord: [nextPointIndex, seriesData[nextPointIndex]], valueIndex: 0 } ], [{ coord: [0, seriesData[nextPointIndex]], valueIndex: 1, value: seriesData[nextPointIndex], lineStyle: { color: color1[0] }, x: '70', label: { show: true, position: 'middle', formatter: '{c}' } }, { coord: [nextPointIndex, seriesData[nextPointIndex]], valueIndex: 1 } ] ]; // 分段线条颜色设置 option.series[0].lineStyle.color = { colorStops: [{ offset: 0, color: color1[0] // 第一段颜色-开始 }, { offset: maxPoint[0] / totalPoint, color: color1[0] // 第一段颜色-结束 }, { offset: maxPoint[0] / totalPoint, color: '#FF0000' // 第二段颜色-开始 }, { offset: maxPoint[1] / totalPoint, color: '#FF0000' // 第二段颜色-结束 }, { offset: maxPoint[1] / totalPoint, color: color1[0] // 第三段颜色-开始 }, { offset: 1, color: color1[0] // 第三段颜色-结束 } ] }; // 设置标注 option.series[0].markPoint.data = [{ name: '', coord: [maxPoint[1], seriesData[maxPoint[1]] + 0.5] }]; option.yAxis.max = maxValue; option.xAxis.data = xAxisDatax; option.series[0].data = seriesData;