一、心电图效果之单线条 ```html:run <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Echarts实现心电图效果</title> <script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.js"></script> </head> <body> <div id="totalFlowRate" style="height:300px;"></div> </body> </html> <script type="text/javascript"> var totalFlowRate = echarts.init(document.getElementById('totalFlowRate')); var xAxisData=[]; var yAxisData=[]; for(var i=500 ;i>0;i--){ xAxisData.push(i+"秒前"); } for(i=1;i<501;i++){ yAxisData.push(Math.round(Math.random()*1000)); } var totalFlowRateOption = { animation:false, title: { text: '总流量(kbps)'/*, left:"110px"*/ }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, grid: { left: 50/*"50px"*/, right: 15/*"15px"*/ }, legend: { data:['当前流量'] }, xAxis: { boundaryGap: false, data: xAxisData }, yAxis: { boundaryGap:false }, series: { symbol:"none",/*去掉小圆点*/ name: '当前流量', type: 'line', itemStyle : { normal : { lineStyle:{ width:2,//折线宽度 color:"#FF0000"//折线颜色 } } }, data: yAxisData/*, smooth:true//0-1之间的数字或true或false,显示为平滑的曲线*/ } }; totalFlowRate.setOption(totalFlowRateOption); setInterval(function(){ yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); totalFlowRate.setOption(totalFlowRateOption); },100); /*setInterval(function(){ yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); var myselfOption = totalFlowRate.getOption(); myselfOption.series[0].data=yAxisData; totalFlowRate.setOption(myselfOption); },100);*/ </script> ``` 二、心电图效果之单线条下有阴影 ```html:run <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Echarts实现心电图效果</title> <script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.js"></script> </head> <body> <div id="totalFlowRate" style="height:300px;"></div> </body> </html> <script type="text/javascript"> var totalFlowRate = echarts.init(document.getElementById('totalFlowRate')); var xAxisData=[]; var yAxisData=[]; for(var i=100 ;i>0;i--){ xAxisData.push(i+"秒前"); } for(i=1;i<101;i++){ yAxisData.push(Math.round(Math.random()*1000)); } setInterval(function(){ yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); var totalFlowRateOption = { animation:false, title: { text: '总流量(kbps)'/*, left:"110px"*/ }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, grid: { left: 50/*"50px"*/, right: 15/*"15px"*/ }, legend: { data:['当前流量'], textStyle:{color:"#66b3ff"}/*图例(legend)说明文字的颜色*/ }, xAxis: { boundaryGap: false, data: xAxisData, splitLine:{show: true}/*网格线*/ }, yAxis: { boundaryGap:false, splitLine:{show: true}/*网格线*/ }, series: { /*itemStyle: {normal: {areaStyle: {type: 'default'}}},*/ itemStyle : { normal : { lineStyle:{ color:'#92c2ff'/*折线的颜色*/ }, color:"#66b3ff"/*图例(legend)的颜色,不是图例说明文字的颜色*/ } }, areaStyle: {normal: { color: new echarts.graphic.LinearGradient( /* 声明渐变色,传入5个参数。 前4个参数用于配置渐变色的起止位置, 这4个参数依次对应右/下/左/上四个方位。 其中0 0 0 1则代表渐变色从正上方开始。 第5个参数则是一个数组, 用于配置颜色的渐变过程,包含起止位置和起止颜色 */ 0, 0, 0, 1, [ {offset: 0, color: '#66b3ff'}, /* {offset: 0.5, color: '#c4e1ff'},*/ {offset: 1, color: '#ecf5ff'} ] ) }}, symbol:"none",/*去掉小圆点*/ name: '当前流量', type: 'line', data: yAxisData/*, smooth:true//显示为平滑的曲线*/ } }; totalFlowRate.setOption(totalFlowRateOption); },100); </script> ``` 三、鼠标移入移出变背景色 ```html:run <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Echarts实现心电图效果</title> <script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.js"></script> </head> <body> <div id="totalFlowRate" style="height:300px;"></div> </body> </html> <script type="text/javascript"> var totalFlowRate = echarts.init(document.getElementById('totalFlowRate')); var xAxisData=[]; var yAxisData=[]; for(var i=100 ;i>0;i--){ xAxisData.push(i+"秒前"); } for(i=1;i<101;i++){ yAxisData.push(Math.round(Math.random()*1000)); } yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); var totalFlowRateOption = { backgroundColor: '#ffffff', animation:false, title: { text: '总流量(kbps)'/*, left:"110px"*/ }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, grid: { left: 50/*"50px"*/, right: 15/*"15px"*/ }, legend: { data:['当前流量'], textStyle:{color:"#66b3ff"}/*图例(legend)说明文字的颜色*/ }, xAxis: { boundaryGap: false, data: xAxisData, splitLine:{show: true}/*网格线*/ }, yAxis: { boundaryGap:false, splitLine:{show: true}/*网格线*/ }, series: { /*itemStyle: {normal: {areaStyle: {type: 'default'}}},*/ itemStyle : { normal : { lineStyle:{ color:'#92c2ff'/*折线的颜色*/ }, color:"#66b3ff"/*图例(legend)的颜色,不是图例说明文字的颜色*/ } }, areaStyle: {normal: { color: new echarts.graphic.LinearGradient( 0, 0, 0, 1, [ {offset: 0, color: '#66b3ff'}, /* {offset: 0.5, color: '#c4e1ff'},*/ {offset: 1, color: '#ecf5ff'} ] ) }}, symbol:"none",/*去掉小圆点*/ name: '当前流量', type: 'line', data: yAxisData/*, smooth:true//显示为平滑的曲线*/ } }; totalFlowRate.setOption(totalFlowRateOption); totalFlowRate.getZr().on('mousemove', function (params) { var pointInPixel = [params.offsetX, params.offsetY]; if (totalFlowRate.containPixel('grid', pointInPixel)) { totalFlowRateOption.backgroundColor = '#F6F8FC'; totalFlowRate.setOption(totalFlowRateOption); } }); totalFlowRate.getZr().on('mouseout', function (params) { var pointInPixel = [params.offsetX, params.offsetY]; if (!totalFlowRate.containPixel('grid', pointInPixel)) { totalFlowRateOption.backgroundColor = '#ffffff'; totalFlowRate.setOption(totalFlowRateOption); } }); </script> ``` 四、心电图效果之7500条数据同页显示 ```html:run <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Echarts实现心电图效果</title> <script src="https://cdn.bootcss.com/echarts/3.7.1/echarts.js"></script> </head> <body> <div id="totalFlowRate" style="height:300px;"></div> </body> </html> <script type="text/javascript"> var totalFlowRate = echarts.init(document.getElementById('totalFlowRate')); var xAxisData=[]; var yAxisData=[]; for(var i=7500 ;i>0;i--){ xAxisData.push(i+"秒前"); } for(i=1;i<7501;i++){ yAxisData.push(Math.round(Math.random()*1000)); } var totalFlowRateOption = { animation:false, title: { text: '总流量(kbps)'/*, left:"110px"*/ }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } }, grid: { left: 50/*"50px"*/, right: 15/*"15px"*/ }, legend: { data:['当前流量'] }, xAxis: { boundaryGap: false, data: xAxisData }, yAxis: { boundaryGap:false }, series: { symbol:"none",/*去掉小圆点*/ name: '当前流量', type: 'line', data: yAxisData/*, smooth:true//显示为平滑的曲线*/ } }; totalFlowRate.setOption(totalFlowRateOption); setInterval(function(){ yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); totalFlowRate.setOption(totalFlowRateOption); },100); /*setInterval(function(){ yAxisData.push(Math.round(Math.random()*1000)); yAxisData.shift(); var myselfOption = totalFlowRate.getOption(); myselfOption.series[0].data=yAxisData; totalFlowRate.setOption(myselfOption); },100);*/ </script> ```