jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點顏色的方法
本文實例講述了jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點顏色的方法。分享給大家供大家參考,具體如下:
1、問題背景
設(shè)計一條折線圖,但是圖形中不用插件自帶的顏色,需要自定義線條和折點的顏色
2、實現(xiàn)源碼
(1)圖形自分配顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-設(shè)置折線圖中折線線條顏色和折線點顏色</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> <div id="line"></div> </body> </html>
(2)線條自定義顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-設(shè)置折線圖中折線線條顏色和折線點顏色</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> <div id="line"></div> </body> </html>
(3)折點自定義顏色
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>echarts-設(shè)置折線圖中折線線條顏色和折線點顏色</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> <div id="line"></div> </body> </html>
3、實現(xiàn)結(jié)果
(1)圖形自分配顏色
(2)線條自定義顏色
(3)折點自定義顏色
4、問題說明
(1)設(shè)置折線線條顏色
lineStyle:{ color:'#00FF00' }
(2)設(shè)置折線折點顏色
itemStyle : { normal : { color:'#00FF00' } }
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
動態(tài)獲取復(fù)選框checkbox選中個數(shù)的jquery代碼
這篇文章主要介紹了jquery中動態(tài)獲取復(fù)選框checkbox選中的個數(shù)的實現(xiàn)代碼,需要的朋友可以參考下2013-06-06jquery請求servlet實現(xiàn)ajax異步請求的示例
下面小編就為大家?guī)硪黄猨query請求servlet實現(xiàn)ajax異步請求的示例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06jQuery實現(xiàn)兩列等高并自適應(yīng)高度
想要使用jQuery實現(xiàn)兩列等高并自適應(yīng)高度,其實也很簡單,原理就是取得左右兩邊的高度,然后判斷這個值,把大的值賦給小的就行了。下面就跟小編一起來看下吧2016-12-12