jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色的方法
本文實(shí)例講述了jQuery插件echarts設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色的方法。分享給大家供大家參考,具體如下:
1、問(wèn)題背景
設(shè)計(jì)一條折線圖,但是圖形中不用插件自帶的顏色,需要自定義線條和折點(diǎn)的顏色
2、實(shí)現(xiàn)源碼
(1)圖形自分配顏色
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>echarts-設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色</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:['銷(xiāo)售量']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value'
},
series: [
{
name:'銷(xiāo)售量',
type:'line',
stack: '銷(xiāo)售量',
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è)置折線圖中折線線條顏色和折線點(diǎn)顏色</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:['銷(xiāo)售量']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value'
},
series: [
{
name:'銷(xiāo)售量',
type:'line',
stack: '銷(xiāo)售量',
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)折點(diǎn)自定義顏色
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>echarts-設(shè)置折線圖中折線線條顏色和折線點(diǎn)顏色</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:['銷(xiāo)售量']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value'
},
series: [
{
name:'銷(xiāo)售量',
type:'line',
stack: '銷(xiāo)售量',
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、實(shí)現(xiàn)結(jié)果
(1)圖形自分配顏色

(2)線條自定義顏色

(3)折點(diǎn)自定義顏色

4、問(wèn)題說(shuō)明
(1)設(shè)置折線線條顏色
lineStyle:{
color:'#00FF00'
}
(2)設(shè)置折線折點(diǎn)顏色
itemStyle : {
normal : {
color:'#00FF00'
}
}
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
使用Jquery實(shí)現(xiàn)點(diǎn)擊文字后變成文本框且可修改
使用Jquery實(shí)現(xiàn)點(diǎn)擊文字變?yōu)槲谋究蛐Ч?,可?duì)文本框文字進(jìn)行修改,具體的實(shí)現(xiàn)思路如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-09-09
jQuery+vue.js實(shí)現(xiàn)的多選下拉列表功能示例
這篇文章主要介紹了jQuery+vue.js實(shí)現(xiàn)的多選下拉列表功能,涉及jQuery+vue.js數(shù)據(jù)綁定及事件響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
基于JQuery的數(shù)字改變的動(dòng)畫(huà)效果--可用來(lái)做計(jì)數(shù)器
之前用javascript做個(gè)計(jì)數(shù)器,從網(wǎng)上搜了搜,找不到合適的,就想著用jquery自己做一個(gè)2010-08-08
jQuery實(shí)現(xiàn)的無(wú)限級(jí)下拉菜單功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的無(wú)限級(jí)下拉菜單,涉及jQuery事件響應(yīng)及頁(yè)面元素屬性動(dòng)態(tài)變換相關(guān)操作技巧,需要的朋友可以參考下2016-09-09
基于jQuery模擬實(shí)現(xiàn)淘寶購(gòu)物車(chē)模塊
這篇文章主要介紹了如何利用jQuery+css+html模擬實(shí)現(xiàn)淘寶購(gòu)物車(chē)模塊,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起動(dòng)手嘗試一下2022-03-03
jQuery實(shí)現(xiàn)打開(kāi)網(wǎng)頁(yè)自動(dòng)彈出遮罩層或點(diǎn)擊彈出遮罩層功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)打開(kāi)網(wǎng)頁(yè)自動(dòng)彈出遮罩層或點(diǎn)擊彈出遮罩層功能,涉及jQuery事件響應(yīng)及窗口元素屬性的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
jquery+json實(shí)現(xiàn)的搜索加分頁(yè)效果
Javascript,json 實(shí)現(xiàn)的js 腳本搜索,加分頁(yè),附源碼2010-03-03
jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級(jí)導(dǎo)航菜單的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級(jí)導(dǎo)航菜單的方法,實(shí)例分析了jQuery操作css及setTimeout等實(shí)現(xiàn)導(dǎo)航菜單的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03

