echarts同一頁面中四個(gè)圖表切換的js數(shù)據(jù)交互方法示例
更新時(shí)間:2018年07月03日 16:52:20 作者:祈澈姑娘
這篇文章主要給大家介紹了關(guān)于echarts同一頁面中四個(gè)圖表切換的js數(shù)據(jù)交互的相關(guān)資料,文中給出了完整的示例代碼供大家參考學(xué)習(xí),對大家的學(xué)習(xí)或者工作具有一定的幫助,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
需求:
點(diǎn)擊tab頁,切換四個(gè)不同的圖表,ajax向后臺請求數(shù)據(jù),展示在四個(gè)不同的圖表中。

其余的就不多說,直接上js代碼了
示例代碼:
$(function() {
$("#heart").on("click", function() {
$('.heart-car').show();
$('.sleep-car').hide();
$('.breathe-car').hide();
$('.sport-car').hide();
});
$("#breathe").on("click", function() {
$('.heart-car').hide();
$('.sleep-car').hide();
$('.breathe-car').show();
$('.sport-car').hide();
});
$("#sport").on("click", function() {
$('.heart-car').hide();
$('.sleep-car').hide();
$('.breathe-car').hide();
$('.sport-car').show();
});
$("#sleep").on("click", function() {
$('.heart-car').hide();
$('.sleep-car').show();
$('.breathe-car').hide();
$('.sport-car').hide();
});
/* 第一個(gè)圖表 */
var aChart = echarts.init(document.getElementById("main"));
function aFun(x_data, y_data) {
aChart.setOption({
title: {
text: '睡眠質(zhì)量監(jiān)測'
},
tooltip: {
trigger: 'axis'
},
xAxis: {
data: x_data
},
yAxis: {
splitLine: {
show: false
}
},
toolbox: {
left: 'center',
feature: {
dataZoom: {
yAxisIndex: 'none'
},
restore: {},
saveAsImage: {}
}
},
dataZoom: [{
startValue: '2014-06-01'
}, {
type: 'inside'
}],
visualMap: {
top: 10,
right: 10,
pieces: [ {
gt: 0,
lte: 1,
color: '#ffde33'
}, {
gt: 1,
lte: 2,
color: '#ff9933'
}, {
gt: 2,
lte: 3,
color: '#cc0033'
}, {
gt: 3,
lte: 4,
color: '#660099'
}],
outOfRange: {
color: '#999'
}
},
series: {
name: '睡眠',
type: 'line',
data: y_data,
markLine: {
silent: true,
data: [{
yAxis: 0
}, {
yAxis: 1
}, {
yAxis: 2
}, {
yAxis: 3
}, {
yAxis: 4
}]
}
}
});
}
/* 第二個(gè)圖表 */
// 折線圖
var bChart = echarts.init(document.getElementById("main2"));
function bFun(x_data, y_data) {
bChart.setOption({
color : [ '#3398DB' ],
tooltip : {
trigger : 'axis',
axisPointer : { // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type : 'shadow' // 默認(rèn)為直線,可選為:'line' | 'shadow'
}
},
legend : {
data : [ '心率值' ]
},
grid : {
left : '3%',
right : '20%',
bottom : '20%',
containLabel : true
},
xAxis : [ {
type : 'category',
data : x_data,
} ],
yAxis : [ { // 縱軸標(biāo)尺固定
type : 'value',
scale : true,
name : '心率值',
max : 140,
min : 0,
splitNumber : 20,
boundaryGap : [ 0.2, 0.2 ]
} ],
series : [ {
name : '心率',
type : 'line',
data : y_data
} ]
}, true);
}
/* 第三個(gè)圖表 */
// 折線圖
var cChart = echarts.init(document.getElementById("main3"));
function cFun(x_data, y_data) {
cChart.setOption({
color : [ '#3398DB' ],
tooltip : {
trigger : 'axis',
axisPointer : { // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
type : 'shadow' // 默認(rèn)為直線,可選為:'line' | 'shadow'
}
},
legend : {
data : [ '呼吸值' ]
},
grid : {
left : '3%',
right : '20%',
bottom : '20%',
containLabel : true
},
xAxis : [ {
type : 'category',
data : x_data,
} ],
yAxis : [ { // 縱軸標(biāo)尺固定
type : 'value',
scale : true,
name : '呼吸值',
max : 50,
min : 0,
splitNumber : 20,
boundaryGap : [ 0.2, 0.2 ]
} ],
series : [ {
name : '呼吸',
type : 'line',
data : y_data
} ]
}, true);
}
/* 第四個(gè)圖表 */
// 基于準(zhǔn)備好的dom,初始化echarts實(shí)例
var dChart = echarts.init(document.getElementById('main4'));
// 指定圖表的配置項(xiàng)和數(shù)據(jù)
function dFun(data) {
dChart.setOption({
tooltip: {
/*返回需要的信息*/
formatter: function(param) {
var value = param.value;
return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 16px;padding-bottom: 7px;margin-bottom: 7px;"> ' + value[0] + " 翻身"
'</div>';
}
},
xAxis: {
show : false,
type: 'time',
name: '時(shí)間軸',
},
yAxis: {
type: 'value',
name: '翻身',
max: 9,
min: 0,
},
series: [{
name: '',
data: data,
type: 'scatter',
symbolSize: 40
}]
});
}
$.ajax({
url : "/bison/stats/mattess/getDetail?id=" + $("#sid").val(),
async : false,
type : 'GET',
dataType : 'json',
success : function(data) {
var status = data.returnData.status;
status.echatX == ''?aFun("[]","[]"):aFun(status.echatX,status.echatY);
var hb = data.returnData.heartBreath;
if(hb.echatX == ''){
bFun("[]","[]");
cFun("[]","[]");
}else{
bFun(hb.echatX, hb.echatY);
cFun(hb.echatX, hb.echatY2);
}
var move = data.returnData.move;
dFun(move);
},
});
})
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
您可能感興趣的文章:
- 簡單實(shí)現(xiàn)js頁面切換功能
- js實(shí)現(xiàn)的鼠標(biāo)滾輪滾動(dòng)切換頁面效果(類似360默認(rèn)頁面滾動(dòng)切換效果)
- js實(shí)現(xiàn)單一html頁面兩套css切換代碼
- 基于JS實(shí)現(xiàn)翻書效果的頁面切換樣式
- 使用AngularJS實(shí)現(xiàn)可伸縮的頁面切換的方法
- javascript單頁面手勢滑屏切換原理詳解
- JavaScript實(shí)現(xiàn)鼠標(biāo)滾輪控制頁面圖片切換功能示例
- jQuery實(shí)現(xiàn)切換頁面過渡動(dòng)畫效果
- jquery結(jié)合html實(shí)現(xiàn)中英文頁面切換
- JavaScript/jQuery實(shí)現(xiàn)切換頁面效果
相關(guān)文章
在JavaScript中遭遇級聯(lián)表達(dá)式陷阱
在JavaScript中遭遇級聯(lián)表達(dá)式陷阱...2007-03-03
JS this關(guān)鍵字在ajax中使用出現(xiàn)問題解決方案
這篇文章主要介紹了JS this關(guān)鍵字在ajax中使用出現(xiàn)問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
Bootstrap 網(wǎng)格系統(tǒng)布局詳解
在平面設(shè)計(jì)中,網(wǎng)格是一種由一系列用于組織內(nèi)容的相交的直線(垂直的、水平的)組成的結(jié)構(gòu)(通常是二維的)。這篇文章主要介紹了Bootstrap 網(wǎng)格系統(tǒng)布局,需要的朋友可以參考下2017-03-03
JavaScript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊導(dǎo)航欄變色特效
本文給大家分享一段基于js代碼實(shí)現(xiàn)的鼠標(biāo)點(diǎn)擊導(dǎo)航欄變色效果,代碼簡單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下
2017-02-02 
