echarts動態載入折線圖資料demo
前面幾節echarts的使用都是靜態常量值得設定,這肯定不能滿足我們在日常開發中的需要,平時專案的資料都是動態的,可變的,所以本章節介紹echarts結合Java 如何動態的載入資料。
=================方式一============
1,新建servelet類EchartsDemo.java和頁面echartsDemo2.jsp。
EchartsDemo.java是一個普通的servelet,在這裡僅僅是舉例,讀者可更換為一個spring的controller或者struts的action。
EchartsDemo.java 程式碼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
package com.test;
/*****
* V型知識庫
* www.vxzsk.com
*
*/
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EchartsDemo extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public EchartsDemo() {
super ();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super .destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this .doPost(request, response);
}
/*****
* V型知識庫
* www.vxzsk.com
*
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String title= "'我是折線圖'" ; //標題
String legend = "['郵件營銷a','聯盟廣告','視訊廣告','直接訪問','搜尋引擎']" ; //折線圖線條
String xAxis= "['週一','週二','週三','週四','週五','週六','週日']" ; //x軸
String series= "["
+ "{"
+ "name:'郵件營銷a',"
+ "type:'line',"
+ "stack: '總量',"
+ "data:[120, 132, 101, 134, 90, 230, 210]"
+ "},"
+ "{"
+ "name:'聯盟廣告',"
+ "type:'line',"
+ "stack: '總量',"
+ "data:[220, 182, 191, 234, 290, 330, 310]"
|