Records how to stitch JSON strings in the background and how to parse them in the foreground, ultimately displaying a pie chart based on JSON data
Using the pie chart to provide the legend data parameter and the data parameter of the series for the Echarts Pieoption, and the two data parameter formats are set by the Echarts control designer to JSON format, [{xx,xx}], so We can use JavaScript to directly receive and reorganize the JSON string from the background, thus directly using the string content, such as the following example with eval ("(" + Jsonstr +) ") parsing the JSON string, followed by Getseriesdata (data) and Getle Genddata (data) reorganizes the Json-formatted data required by data, and is used directly at legend: {data:getlegenddata (name)}.
1. Background stitching Json String
String hql = ""; List List = Session.createsqlquery (HQL). List (); String jsonstr = "["; for (int i=0; I < list.size (); i + +) {//Spell JSON string object[] obj = (object[]) list.get (i); Jsonstr + = "{\" name\ ": \" "+ Typemap.gettypename (Integer.parseint ( Obj[0].tostring ())) + "\", "+" \ "nvalue\": \ "" + obj[1].tostring () + "\"}, ";} Jsonstr = jsonstr.substring (0, Jsonstr.length ()-1);//Remove the last one, the number jsonstr + = "]";
2. echarts.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "GBK"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
End.
"Web Front end" Echarts using notes