<Scripttype= "Text/javascript">$ (). Ready (function() { varMyChart=Echarts.init (document.getElementById ('Main')); //Chart Display tip informationmychart.showloading (); //Define Chart Optionsoption={tooltip: {trigger:'Axis', Axispointer: {//axis indicator, axis trigger validType:'Shadow' //The default is straight line, optional: ' Lines ' | ' Shadow '}}, Legend: {data: []}, Grid: {left:'3%', right:'4%', bottom:'3%', Containlabel:true}, Xaxis: {type:'value'}, YAxis: {type:'category', data: []}, Series: []}; //getting data through Ajax$.ajax ({type:"Post", Async:false, //Synchronous ExecutionURL:"showechartfoldbar.action", DataType:"JSON", //The returned data is in JSON formSuccess:function(Result) {if(Result) {//assigns the returned category and series objects to the category and series within the options object //because Xaxis is an array here needs to be the form of xaxis[i]Option.legend.data=Result.legend; Option.yAxis.data=result.category; varSerisdata=result.series[0].data; vardatas= []; for ( varI= 0; I<serisdata.length; I++) {Datas.push ({name:serisdata[i].name, Type:serisdata[i].type, Stack:serisdata[i].stack, Label: {normal: {show:true, Position:'Insideright'}}, Data:serisdat A[i].data,}); } option.series=datas; Mychart.hideloading (); mychart.setoption (option); }}, Error:function(errormsg) {alert ("Chart request data failed!"); } }); }); </Script>
@RequestMapping ("/showechartfoldbar") @ResponseBody Publicechartdata Foldbardata () {List<String> legend =NewArraylist<string>(); List<Visit> vis1 = visitbiz.findbycondition (NewVisit (NULL, "Monday",NULL,NULL)); for(Visit visit:vis1) {Legend.add (Visit.getname ()); } List<String> category =NewArraylist<string>(); List<Visit> Vis2 = visitbiz.findbycondition (NewVisit (NULL,NULL,NULL, "Mail Marketing")); for(Visit visit:vis2) {Category.add (Visit.getweek ()); } List<Map> Serisdata=NewArraylist<map>(); List<String> name =Visitbiz.selectname (); for(String str:name) {map map=NewHashMap (); Map.put ("Name", str); List<Visit> lis = Visitbiz.findbycondition (NewVisit (NULL,NULL,NULL, str)); List<Long> Data=NewArraylist<long>(); for(Visit visit:lis) {Data.add (Visit.getcount ()); } map.put ("Data", data); Map.put ("Type", "Bar"); Map.put ("Stack", "Total"); Serisdata.add (map); } List<Series> Series =NewArraylist<series> ();//OrdinateSeries.add (NewSeries (NULL,NULL, Serisdata)); Echartdata Data=NewEchartdata (legend,category, series); returndata; }
Public class Visit { private Integer ID; Private String week; Private Long count; Private String name;
Using ECharts3.0 to draw stacked bar charts based on the SPRINGMVC framework (next)