本文主要介紹了jQuery插件echarts設定折線圖中折線線條顏色和折線點顏色的方法,結合實例形式分析了jQuery圖表插件echarts設置折線圖的相關操作技巧,需要的朋友可以參考下,希望能幫助大家。
1、問題背景
設計一條折線圖,但是圖形中不用插件自帶的顏色,需要自訂線條和折點的顏色
2、實作原始碼
(1)圖形自分配顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-设置折线图中折线线条颜色和折线点颜色</title> <link rel="shortcut icon" href="../js/echarts-2.2.7/doc/asset/ico/favicon.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <script type="text/javascript" src="../js/echarts-2.2.7/doc/asset/js/jquery.min.js" ></script> <script type="text/javascript" src="../js/echarts-2.2.7/doc/example/www2/js/echarts-all.js" ></script> <style> body,html{ width: 99%; height: 99%; font-family: "微软雅黑"; font-size: 12px; } #line{ width: 100%; height: 100%; } </style> <script> $(function(){ var chart = document.getElementById('line'); var echart = echarts.init(chart); var option = { title: { text: '' }, tooltip: { trigger: 'axis' }, legend: { data:['销售量'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: ['周一','周二','周三','周四','周五','周六','周日'] }, yAxis: { type: 'value' }, series: [ { name:'销售量', type:'line', stack: '销售量', data:[220, 132, 601, 314, 890, 230, 510] } ] }; echart.setOption(option); }); </script> </head> <body> <p id="line"></p> </body> </html>
(2)線條自訂顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-设置折线图中折线线条颜色和折线点颜色</title> <link rel="shortcut icon" href="../js/echarts-2.2.7/doc/asset/ico/favicon.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <script type="text/javascript" src="../js/echarts-2.2.7/doc/asset/js/jquery.min.js" ></script> <script type="text/javascript" src="../js/echarts-2.2.7/doc/example/www2/js/echarts-all.js" ></script> <style> body,html{ width: 99%; height: 99%; font-family: "微软雅黑"; font-size: 12px; } #line{ width: 100%; height: 100%; } </style> <script> $(function(){ var chart = document.getElementById('line'); var echart = echarts.init(chart); var option = { title: { text: '' }, tooltip: { trigger: 'axis' }, legend: { data:['销售量'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: ['周一','周二','周三','周四','周五','周六','周日'] }, yAxis: { type: 'value' }, series: [ { name:'销售量', type:'line', stack: '销售量', itemStyle : { normal : { lineStyle:{ color:'#00FF00' } } }, data:[220, 132, 601, 314, 890, 230, 510] } ] }; echart.setOption(option); }); </script> </head> <body> <p id="line"></p> </body> </html>
(3)折點自訂顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-设置折线图中折线线条颜色和折线点颜色</title> <link rel="shortcut icon" href="../js/echarts-2.2.7/doc/asset/ico/favicon.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" > <script type="text/javascript" src="../js/echarts-2.2.7/doc/asset/js/jquery.min.js" ></script> <script type="text/javascript" src="../js/echarts-2.2.7/doc/example/www2/js/echarts-all.js" ></script> <style> body,html{ width: 99%; height: 99%; font-family: "微软雅黑"; font-size: 12px; } #line{ width: 100%; height: 100%; } </style> <script> $(function(){ var chart = document.getElementById('line'); var echart = echarts.init(chart); var option = { title: { text: '' }, tooltip: { trigger: 'axis' }, legend: { data:['销售量'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: ['周一','周二','周三','周四','周五','周六','周日'] }, yAxis: { type: 'value' }, series: [ { name:'销售量', type:'line', stack: '销售量', itemStyle : { normal : { color:'#00FF00', lineStyle:{ color:'#00FF00' } } }, data:[220, 132, 601, 314, 890, 230, 510] } ] }; echart.setOption(option); }); </script> </head> <body> <p id="line"></p> </body> </html>
3、實作結果
(1)圖形自指派顏色
( 2)線條自訂顏色
(3)折點自訂顏色
##4、問題說明
(1)設定折線線條顏色lineStyle:{ color:'#00FF00' }
itemStyle : { normal : { color:'#00FF00' } }
以上是echarts設定折線線條顏色和折線點顏色的實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!