echart使用例子

来源:互联网 发布:怎么避免mac涂层脱落 编辑:程序博客网 时间:2024/06/06 04:39

先看看工程目录,将百度的工程文件复制到自己的工程里面,这里不再赘述。


 然后根据需要选取echart图表    示例地址

新建一个Servelet,jsp文件使用Ajax.

package com.lv.controller;import java.io.IOException;import java.io.PrintWriter;import java.util.LinkedHashMap;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;public class EchartsServlet extends HttpServlet {private static final long serialVersionUID = 1L;/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. *  * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request, response);}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. *  * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//设置返回值的编码格式//这个是可以直接使用网页访问URL,然后返回值也不会出现中文乱码 所以(1)比二好response.setContentType("text/html; charset=utf-8");//(1)//response.setCharacterEncoding("utf-8"); //(2)两者选其一LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();map.put("text","人物关系:自定义");map.put("subtext","数据仅用于测试");//调用JSONArray.fromObject方法把map中的对象转化为JSON格式的数组JSONArray json=JSONArray.fromObject(map);System.out.println(json.toString());//返回给前段页面PrintWriter out = response.getWriter();  out.println(json);out.flush();  out.close();   }}



0 0
原创粉丝点击