jQuery插件echarts設置折線圖中折線線條顏色和折線點顏色的方法
本文實例講述了jQuery插件echarts設置折線圖中折線線條顏色和折線點顏色的方法。分享給大家供大家參考,具體如下:
1、問題背景
設計一條折線圖,但是圖形中不用插件自帶的顏色,需要自定義線條和折點的顏色
2、實現(xiàn)源碼
(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>
<div id="line"></div>
</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>
<div id="line"></div>
</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>
<div id="line"></div>
</body>
</html>
3、實現(xiàn)結果
(1)圖形自分配顏色

(2)線條自定義顏色

(3)折點自定義顏色

4、問題說明
(1)設置折線線條顏色
lineStyle:{
color:'#00FF00'
}
(2)設置折線折點顏色
itemStyle : {
normal : {
color:'#00FF00'
}
}
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jquery中Ajax用法總結》、《jQuery表格(table)操作技巧匯總》、《jQuery擴展技巧總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
使用Jquery實現(xiàn)點擊文字后變成文本框且可修改
使用Jquery實現(xiàn)點擊文字變?yōu)槲谋究蛐Ч?,可對文本框文字進行修改,具體的實現(xiàn)思路如下,感興趣的朋友可以參考下,希望對大家有所幫助2013-09-09
jQuery+vue.js實現(xiàn)的多選下拉列表功能示例
這篇文章主要介紹了jQuery+vue.js實現(xiàn)的多選下拉列表功能,涉及jQuery+vue.js數(shù)據(jù)綁定及事件響應相關操作技巧,需要的朋友可以參考下2019-01-01
基于JQuery的數(shù)字改變的動畫效果--可用來做計數(shù)器
之前用javascript做個計數(shù)器,從網上搜了搜,找不到合適的,就想著用jquery自己做一個2010-08-08
jQuery實現(xiàn)打開網頁自動彈出遮罩層或點擊彈出遮罩層功能示例
這篇文章主要介紹了jQuery實現(xiàn)打開網頁自動彈出遮罩層或點擊彈出遮罩層功能,涉及jQuery事件響應及窗口元素屬性的相關操作技巧,需要的朋友可以參考下2017-10-10
jQuery實現(xiàn)仿美橙互聯(lián)兩級導航菜單的方法
這篇文章主要介紹了jQuery實現(xiàn)仿美橙互聯(lián)兩級導航菜單的方法,實例分析了jQuery操作css及setTimeout等實現(xiàn)導航菜單的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03

