JSP用echarts实现报表统计
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Echartsä¸è¬å¨æ°æ®æ¥è¡¨ä¸æè½å±ç°ä»çææï¼ä»å¤©ç±ç«ææ¯é¢éå°ç¼å°±ä¸ºå¤§å®¶å¸¦æ¥äºJSPç¨echartså®ç°æ¥è¡¨ç»è®¡ï¼æä¸ç¹çåèä»·å¼ï¼å¼å¾æ们æ¶èå¦ä¹ ã
å¼å§ä¸ä»£ç ã
é¦å æ¯tagï¼è¿ä¸ªä¸è¥¿ï¼å¤§å¦ä¹åï¼å ä¹ä¸æä¹ç¨äºï¼æ²¡æ³å°ç°å¨åç¨å°äºã
åtagéè¦å¼å ¥jstlå ï¼è°·æä¸å°±æäºã1.2ä¹åéè¦ä¸¤ä¸ªå ï¼ä¸ä¸ªjstlï¼ä¸ä¸ªstandardã1.2ä¹åè²ä¼¼å并为ä¸ä¸ªäºãè¿å¥çåæ³ä¹æç¹ä¸åã为é²ä¸ä¸ï¼ææ¯å¼å ¥ç两个å ã
使ç¨ajax请æ±ï¼éè¦å¼å ¥jqueryçå ï¼å¼å ¥echartsçæ¶åï¼åæ¶å¼å ¥è¿ä¸ªã
å¨ä¸é¢ä»£ç ä¸ï¼æ主è¦çè¿æ¯æ 红çé£æ®µï¼seriesæ¯ä¸ä¸ªæ°ç»ï¼åå°å å ¥å¤ç»æ°æ®çæ¶åï¼è¿ééè¦éåååºã
jsp页é¢å¼å ¥è¯¥æ ç¾ï¼
å端çé¨åå°æ¤ç®æ¯å®æï¼ç¶åå°±æ¯åå°é¨åäºã
åå°ç¨ä¸¤ä¸ªjava对象ï¼å°è£ ä¸ä¸è¦ä¼ éçæ°æ®
package bean.newseries; import java.util.ArrayList; import java.util.List; /** * Created by on 2014/11/25. */ public class Echarts { public Listlegend = new ArrayList ();//æ°æ®åç» public List axis = new ArrayList ();//横åæ public List series = new ArrayList ();//纵åæ public Echarts(List legendList, List categoryList, List seriesList) { super(); this.legend = legendList; this.axis = categoryList; this.series = seriesList; } }
è¿éæ¾seriesçå ·ä½æ°æ®ï¼
package bean.newseries; import java.util.List; /** * Created by on 2014/11/25. */ public class Series { public String name; public String type; public Listdata; public Series(String name, String type, List data) { this.name = name; this.type = type; this.data = data; } }
åå°ä¸å¡ä¸ï¼å°èªå·±çæ°æ®ï¼æ¾å°å¯¹è±¡ä¸ï¼ç¶å转æ¢æjsonæ ¼å¼ï¼
package tagservlet; import bean.newseries.Echarts; import bean.newseries.Series; import com.fasterxml.jackson.databind.ObjectMapper; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Created by on 2014/11/24. */ public class NewTagServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Listlegend=new ArrayList (Arrays.asList(new String[]{"æé«å¼","æä½å¼"})); List axis=new ArrayList (Arrays.asList(new String[]{"å¨ä¸","å¨äº","å¨ä¸","å¨å","å¨äº","å¨å ","å¨æ¥"})); List series=new ArrayList (); series.add(new Series("æé«å¼","line",new ArrayList (Arrays.asList(21,23,28,26,21,33,44)))); series.add(new Series("æä½å¼","line",new ArrayList (Arrays.asList(-2,-12,10,0,20,11,-6)))); Echarts echarts=new Echarts(legend,axis,series); ObjectMapper objectMapper=new ObjectMapper(); System.out.println(objectMapper.writeValueAsString(echarts)); response.setContentType("text/html;charset=utf-8"); PrintWriter out=response.getWriter(); out.println(objectMapper.writeValueAsString(echarts)); out.flush(); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
ææå¾å¦ä¸ï¼
æ谢大家è§çç±ç«ææ¯é¢éå°ç¼å°ç¼ä»ç»çJSPç¨echartså®ç°æ¥è¡¨ç»è®¡ï¼ä¸ç¥éå°ä¼ä¼´ä»¬å¯¹æ¤æ没ä»ä¹çæå¢?æçè¯å¯ä»¥åè¯å°ç¼ï¼å°ç¼å°ä¸ºä½ ç«è¯æå¡ã
上一篇:JSP测试函数的运行速度方法