一、心電圖效果之單線條 ```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> ```