Echarts教程之通過(guò)Ajax實(shí)現(xiàn)動(dòng)態(tài)加載折線圖的方法
一、GIF圖

二、前臺(tái)代碼
// 調(diào)用方法
hotlineLine();
// 定時(shí)刷新
setInterval(function () {
hotlineLine();
},5000);
function hotlineLine(){
// 初始化圖表元素
var hotlineLine = echarts.init(document.getElementById('hotlineLine_id'));
$.get('${pageContext.request.getContextPath()}/m/hotline.do', function (res) {
var option = {
// 提示框組件,鼠標(biāo)經(jīng)過(guò)餅圖時(shí)會(huì)出現(xiàn)提示框
tooltip: {
// 觸發(fā)類型
// 坐標(biāo)軸觸發(fā),主要在柱狀圖,折線圖等會(huì)使用類目軸的圖表中使用。
trigger: 'axis'
},
// 每條折線的顏色
color: ['#87CEFA', '#9AFF9A', '#C0FF3E','#DB7093'],
// 圖例組件
legend: {
// 內(nèi)容
data:['呼入', '呼出', '應(yīng)答', '用戶放棄'],
// 樣式
textStyle:{
fontSize:10,
color:'#66ffff'
},
// 上距離,類似css中的margin
top:'5%'
},
// 網(wǎng)格
grid: {
// 左距離
left: '7%',
right: '5%',
bottom: '10%',
top:'20%'
},
// 橫坐標(biāo)
xAxis: {
// 類型
type: 'category',
// 刻度
data: ['08:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '24:00'],
// 樣式
axisLine:{
// 橫坐標(biāo)線的顏色
lineStyle:{
color:'#66ffff'
}
}
},
yAxis: {
type: 'value',
name: '次數(shù)',
axisLabel: {
formatter: '{value}'
},
axisLine:{
lineStyle:{
color:'#66ffff'
}
},
splitLine:{
show: true,
lineStyle:{
color:'#66ffff'
}
}
},
series: [
{
name:'呼入',
type:'line',
data:res[3]
},
{
name:'呼出',
type:'line',
data:res[2]
},
{
name:'應(yīng)答',
type:'line',
data:res[1]
},
{
name:'用戶放棄',
type:'line',
data:res[0]
}
],
// 文本標(biāo)簽
label: {
//是否展示
show: true,
position: 'top',
textStyle: {
fontWeight:'bolder',
fontSize : '12',
fontFamily : '微軟雅黑',
color:defaultColor
}
}
};
hotlineLine.setOption(option);
});
}
<div class="rightMain01-sub03 box-border">
<div class="box-title">話務(wù)指標(biāo)趨勢(shì)圖</div>
<div class="rightMain01-sub03-data">
<div id="hotlineLine_id" style="height:340px;"></div>
</div>
</div>
三、后臺(tái)代碼
List<List<Integer>> hotlineList = new ArrayList<List<Integer>>();
@RequestMapping("/m/hotline.do")
@ResponseBody
public JSONArray hotline() {
List<List<Integer>> returnList = new ArrayList<List<Integer>>();
if (hotlineList.size() == 0 || hotlineList.get(0).size() >= 9) {
hotlineList.clear();
for (int i = 0; i < 4; i++) {
List<Integer> l = new ArrayList<Integer>();
l.add(i * 5 + AlexUtils.getRandomInteger(0, 5));
hotlineList.add(l);
}
}
for (int i = 0; i < hotlineList.size(); i++) {
List<Integer> list = hotlineList.get(i);
int thisSize = list.size();
if (thisSize < 5) {
list.add(list.get(thisSize - 1) + AlexUtils.getRandomInteger(1, 5));
} else {
list.add(list.get(thisSize - 1) - AlexUtils.getRandomInteger(1, 5));
}
returnList.add(list);
}
hotlineList = returnList;
return JSONArray.fromObject(returnList);
}
public static int getRandomInteger(int min, int max) {
int diff = max - min;
return min + new Random().nextInt(diff);
}
數(shù)據(jù)格式:
1.[[1,3,4,5,7],[6,9,11,12,13],[10,11,12,13,16],[16,19,21,22,24]]
總結(jié)
以上所述是小編給大家介紹的Echarts教程之通過(guò)Ajax實(shí)現(xiàn)動(dòng)態(tài)加載折線圖的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
IE7下ajax之open Method New的說(shuō)明
IE7下ajax之open Method New的說(shuō)明...2007-06-06
Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)
這篇文章主要介紹了Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)的相關(guān)資料,需要的朋友可以參考下2016-03-03
用AJAX實(shí)現(xiàn)頁(yè)面登陸以及注冊(cè)用戶名驗(yàn)證的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇用AJAX實(shí)現(xiàn)頁(yè)面登陸以及注冊(cè)用戶名驗(yàn)證的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
健壯的AJAX源碼學(xué)習(xí)應(yīng)用示例
健壯的AJAX源碼學(xué)習(xí)應(yīng)用示例...2006-09-09
詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法
今天小編就為大家分享一篇詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
琥珀無(wú)限級(jí)分類聯(lián)動(dòng)菜單AJAX版
琥珀無(wú)限級(jí)分類聯(lián)動(dòng)菜單AJAX版...2006-11-11

