Toggle navigation
如何实现柱状图和折线图的部分虚线功能
By
大***e
2019-06-11 15:14:25
脚本
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 dateData = ["2019-06-01", "2019-06-02", "2019-06-03", "2019-06-04", '2019-06-05', '2019-06-06', "2019-06-07"]; var dataD = [22, 34, 44, 15, 15, 22, 16, 24, 23, 20, 8, 9]; var chooseDate = "2019-06-04"; var len; for (var i = 0; i < dateData.length; i++) { if (chooseDate == dateData[i]) { len = i; break; } } var newDataD = []; for (var j = 0; j < len; j++) { newDataD.push(dataD[j]); } for (var k = len; k < dataD.length; k++) { var data2 = {}; data2.value = dataD[k]; data2.itemStyle = { normal: { color: '#fff', borderType: "dashed", barBorderColor: 'red', barBorderWidth: 3, barBorderRadius: 0 } } newDataD.push(data2) data2 = {}; } var d = [11.0, 4.9, 7.0, 23.2, 25.6, 76.7, 11.6, 16.2, 32.6, 20.0, { itemStyle: { normal: { color: '#fff', borderType: "dashed" } }, value: 21, }, { value: 22, itemStyle: { normal: { color: '#fff', borderType: "dashed" } } }] var seriesData = [{ name: '蒸发量', type: 'bar', itemStyle: { normal: { color: "blue", barBorderColor: 'blue', barBorderWidth: 3, barBorderRadius: 0, borderType: "solid" } }, data: d, }, { name: '降水量', type: 'bar', data: newDataD }, { name: '平均温度', type: 'line', smooth: true, yAxisIndex: 1, itemStyle: { normal: { color: "#000", lineStyle: { type: "solid", width: 2 } } }, data: [1100, 1202, 1303, 1405, 1300, 1020, 2030, 2340, 2300, "-", "-", "-"] }, { name: '平均温度', type: 'line', smooth: true, yAxisIndex: 1, itemStyle: { normal: { color: "#000", lineStyle: { type: "dotted", width: 2 } } }, data: ["-", "-", "-", "-", "-", "-", "-", "-", 2300, 1005, 1200, 602] } ] option = { tooltip: { show: true, trigger: 'axis', axisPointer: { // type: 'cross', crossStyle: { // color: '#999' } }, formatter: function(params, ticket, callback) { console.log(params, 'params') var htmlStr = ''; var valMap = {}; for (var i = 0; i < params.length; i++) { var param = params[i]; var xName = param.name; //x轴的名称 var seriesName = param.seriesName; //图例名称 var value = param.value; //y轴值 var color = param.color; //图例颜色 if (seriesName == "蒸发量") { color = "blue"; } else if (seriesName == "降水量") { color = "red" } //过滤无效值 if (value == '-') { continue; } //过滤重叠值 if (valMap[seriesName] == value) { continue; } if (i === 0) { htmlStr += xName + '
'; //x轴的名称 } htmlStr += '
'; //为了保证和原来的效果一样,这里自己实现了一个点的效果 htmlStr += '
'; //圆点后面显示的文本 // htmlStr += seriesName + ':' + value; if (seriesName == "平均温度") { var value1 = ""; value = value + ""; if (value.length > 3) { value1 = value.slice(0, 2) + ":" + value.slice(-2); } else { value1 = "0" + value.slice(0, 1) + ":" + value.slice(-2); } htmlStr += seriesName + ':' + value1; } else { htmlStr += seriesName + ':' + value; } htmlStr += '
'; valMap[seriesName] = value; } return htmlStr; } }, grid: { bottom: "20%", left: 30, right: 30, containLabel: true }, legend: { bottom: "10%", data: ['蒸发量', '降水量', '平均温度'] }, xAxis: [{ axisLabel: { // padding: [0, 110, 0,50], // 上右下左 // interval :10 // margin :1 }, type: 'category', axisLine: { show: true, // onZero :false, // lineStyle:{width:1} }, // nameLocation :"middle", data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], axisPointer: { // type: 'shadow' }, splitLine: { //网格线 show: false }, axisTick: { //y轴刻度线 show: false, alignWithLabel: true, }, boundaryGap: true }], yAxis: [{ type: 'value', name: '水量', axisLabel: { formatter: '{value} ml' }, splitLine: { //网格线 show: false } }, { type: 'value', name: '温度', axisLabel: { formatter: '{value} °C' }, splitLine: { //网格线 show: false }, axisTick: { //y轴刻度线 show: false } }, ], series: seriesData, dataZoom: [{ type: 'slider', show: true, xAxisIndex: [0], start: 1, end: 100, bottom: "0", }, { bottom: "10%", type: 'inside', xAxisIndex: [0], start: 1, end: 35 } ], };