说明:本实例使用的是echart3,jquery1.8.11)struts的web.xml配置代码如下:<?xml version="1.0"encoding="UTF-8"?><web-app xmlns:xsi="/2001/XMLSchema-instance"xmlns="/xml/ns/javaee"xsi:schemaLocation="/xml/ns/javaee/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0"><display-name>struts2</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><!-- struts2配置 --><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecu teFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>2)struts.xml代码<?xml version="1.0"encoding="UTF-8"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""/dtds/struts-2.3.dtd"><struts><!-- <package name="default"namespace="/student" extends="struts-default">配置Action<action name="studentAdd" class="struts2.action.StudentController" method="studentAdd">根据我们业务方法返回的字符串来定义跳转的视图<result name="success"></result><result name="error"/><result name="none"/></action></package> --><package name="tb"namespace="/echarts"extends="struts-default"><!-- 配置Action --><action name="zzt"class="struts2.action.EchartsAction"method="getZzt"> <!-- 根据我们业务方法返回的字符串来定义跳转的视图 --><result name="success"></result><result name="error"/><result name="none"/></action></package><!-- Add packages here --></struts>3)EchartsAction :package struts2.action;import common.controller.BaseController;publicclass EchartsAction extends BaseController{/*private String json = "[{\"鞋\":\"80\"},{\"衬衫\":\"50\"},{\"外套\":\"75\"},{\"牛仔裤\":\"100\"}]";*/private String json= "[{\"item\":\"鞋\",\"saleNum\":\"80\"},{\"item\":\"衬衫\",\"saleNum\":\"100\"},"+ "{\"item\":\"外套\",\"saleNum\":\"90\"},{\"item\":\"牛仔裤\",\"saleNum\":\"70\"}]";publicvoid getZzt(){try {getPrintWriter().print(json);} catch (Exception e) {e.printStackTrace();}}}4)页面源代码:<%@page language="java"contentType="text/html; charset=utf-8"pageEncoding="utf-8"%><%String contextPath = request.getContextPath();%><!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01Transitional//EN""/TR/html4/loose.dtd"><html><head><meta charset="utf-8"/><title></title><script type="text/javascript"src="resources/js/jquery-1.8.1.min.js"></s cript><script type="text/javascript"src="resources/js/echarts.js"></script> </head><style type="text/css">td{border-right:1px solid #555 border-bottom:1px solid #555; padding:6px 10px 6px 10px;}</style><script type="text/javascript">var contextPath = '<%=contextPath%>';$(function(){loadImage();});var option = {title: {text: '深圳月最低生活费组成(单位:元)',subtext: 'From ExcelHome',sublink: '/1341556070/AjQH99che'},tooltip : {trigger: 'axis',axisPointer : { // 坐标轴指示器,坐标轴触发有效type : 'shadow'// 默认为直线,可选为:'line' | 'shadow'},formatter: function (params) {var tar = params[1];return + '<br/>' + tar.seriesName + ' : ' + tar.value;}},grid: {left: '3%',right: '1%',bottom: '3%',containLabel: true},xAxis: {type : 'category',splitLine: {show:false},data:[],},yAxis: {type : 'value'},series : [{name: '辅助',type: 'bar',stack: '总量',itemStyle: {normal: {barBorderColor: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)'},emphasis: {barBorderColor: 'rgba(0,0,0,0)', color: 'rgba(0,0,0,0)'}},data: [0, 0, 0, 0, 0, 0]},{name: '销量',type: 'bar',stack: '总量',label: {normal: {show: true,position: 'inside'}},data:[],barWidth:40}]};function loadImage(){var myChart = echarts.init(document.getElementById('pieCharts'),'macarons');var url= contextPath + "/echarts/zzt?random=" + new Date().getTime();jQuery.ajax({url: url,dataType:"json",type:"post",success:function(data){for(var i=0;i<data.length;i++){option.xAxis.data.push(data[i].item);(option.series[1].data).push(parseInt(data[i].saleNum));}myChart.setOption(option);},error:function(data){alert("网络错误!");}});}</script><body><div id="pieCharts"style="width:600px;height:400px;"></div></body> </html>。