您好,登錄后才能下訂單哦!
使用Echarts怎么動態加載多條折線圖?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
//氣象數據 function serchQx(beginTime, endTime, str, parameter) { $("#rr").html("");//將循環拼接的字符串插入下拉列表 var t = $("#imageParameter").val(); $ .ajax({ type : "POST", data : { "str" : str, "beginTime" : beginTime, "endTime" : endTime, "parameter" : parameter, "t" : t }, url : "${pageContext.servletContext.contextPath}/dataAnalysis/serch.action", success : function(result) { var aa = []; var tmp=[]; if (parameter == 1) { aa.push('單位(℃)'); //option.yAxis[0].name = aa; } else if (parameter == 2) { aa.push('單位(%)'); //option.yAxis[0].name = aa; } else if (parameter == 3) { aa.push('單位(KPa)'); //option.yAxis[0].name = aa; } else if (parameter == 4) { aa.push('單位(w/㎡)'); //option.yAxis[0].name = aa; } else if (parameter == 5) { aa.push('單位(mm)'); //option.yAxis[0].name = aa; } else if (parameter == 6) { aa.push('單位(m/s)'); //option.yAxis[0].name = aa; } //處理數據 //將從后臺接收的json字符串轉換成json對象 var jsonobj = eval("(" + result + ")"); //給圖標標題賦值 //option.legend.data = jsonobj.legend; //讀取橫坐標值 //option.xAxis[0].data = jsonobj.axis; var series_arr = jsonobj.series; //驅動圖表生成的數據內容,數組中每一項代表一個系列的特殊選項及數據 for (var i = 0; i < series_arr.length; i++) { var datas=[]; for(var j=0;j<series_arr[i].data.length;j++){ var n=series_arr[i].data[j]; var time=series_arr[i].time[j]; var data=[time,n]; datas.push(data); } //轉換Series temp = { name: series_arr[i].name, type: "line", data: datas }; tmp.push(temp) //option.series.push(temp); } myChart.clear(); //myChart.setOption(option,true); myChart.setOption({ //加載數據圖表 color : colors, tooltip : { trigger : 'axis' }, dataZoom : { show : true, start : 0, realtime : true }, legend : { data : jsonobj.legend }, grid : { top : 70, bottom : 50 }, calculable: true, xAxis : [ { type : 'time', boundaryGap : [ 0, 100 ], axisLabel : { textStyle : { fontSize : "10px" } } } ], yAxis : [ { name : aa, type : 'value', } ], series : tmp},true); } }) }
后臺封裝的Series
/** * */ package com.myhope.domain; import java.util.List; /** * Description:<br/> * Copyright (c) , 2017, Jansonxu <br/> * This program is protected by copyright laws. <br/> * Program Name:Series<br/> * Date:2019年1月14日 * * @author * @version : 1.0 */ public class Series { private String name; private String type; private List<Double> data; private List<String> time; public Series(String name, String type, List<Double> data, List<String> time) { super(); this.name = name; this.type = type; this.data = data; this.time = time; } public List<String> getTime() { return time; } public void setTime(List<String> time) { this.time = time; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } public List<Double> getData() { return data; } public void setData(List<Double> data) { this.data = data; } public Series() { super(); } @Override public String toString() { return "Series [name=" + name + ", type=" + type + ", data=" + data + ", time=" + time + "]"; } }
后臺封裝Echarts
/** * */ package com.myhope.domain; import java.util.List; /** * Description:<br/> * Copyright (c) , 2017, Jansonxu <br/> * This program is protected by copyright laws. <br/> * Program Name:Echarts<br/> * Date:2019年1月14日 * * @author * @version : 1.0 */ public class Echarts { private List<String> legend;//name private List<String> axis ;//橫坐標 private List<Series> series;//數據項 private List<DataAnalysisTable> dataAnalysisTables; public Echarts(List<String> legend, List<String> axis, List<Series> series, List<DataAnalysisTable> dataAnalysisTables) { super(); this.legend = legend; this.axis = axis; this.series = series; this.dataAnalysisTables = dataAnalysisTables; } public Echarts() { super(); } public List<String> getLegend() { return legend; } public void setLegend(List<String> legend) { this.legend = legend; } public List<String> getAxis() { return axis; } public void setAxis(List<String> axis) { this.axis = axis; } public List<Series> getSeries() { return series; } public void setSeries(List<Series> series) { this.series = series; } public List<DataAnalysisTable> getDataAnalysisTables() { return dataAnalysisTables; } public void setDataAnalysisTables(List<DataAnalysisTable> dataAnalysisTables) { this.dataAnalysisTables = dataAnalysisTables; } @Override public String toString() { return "Echarts [legend=" + legend + ", axis=" + axis + ", series=" + series + ", dataAnalysisTables=" + dataAnalysisTables + "]"; } }
Action封裝
將對應的東西傳入頁面即可
Echarts echarts = new Echarts(legend, newAxis, series,); String jsonString = com.alibaba.fastjson.JSONObject.toJSONString(echarts);
初始化Echarts文件
var dom = document.getElementById("xsl"); var myChart = echarts.init(dom); myChart.showLoading({ text : "圖表數據正在努力加載..." }); var app = {}; app.title = '多 X 軸示例'; var colors = [ '#5793f3', '#d14a61', '#675bba', "#00FF00", "#FFFF00" ]; option = { color : colors, tooltip : { trigger : 'axis' }, dataZoom : { show : true, start : 0, realtime : true }, legend : { data : [] }, grid : { top : 70, bottom : 50 }, calculable: true, xAxis : [ { type : 'time', boundaryGap : [ 0, 100 ], axisLabel : { textStyle : { fontSize : "10px" } } } ], yAxis : [ { name : [], type : 'value', } ], series : [] }; myChart.clear(); myChart.setOption(option, true);
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。