"Web Front end" Echarts using notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.