[WEB Front-end] eCharts use notes, webecharts

Source: Internet
Author: User

[WEB Front-end] eCharts use notes, webecharts

Record how to splice a Json string in the background, parse and use it in the foreground, and finally display the pie chart based on Json data

The pie chart mainly provides legend data parameters and series data parameters for the pieOption of echarts. The two data parameter formats are set by the echarts control designer to json format, that is, [{xx, xx}], so we can use javascript to directly receive and reorganize the json string sent from the background, so as to directly use the string content, as shown in the following example using eval ("(" + jsonStr + ") ") parse the Json string, use getSeriesData (data) and getlegendData (data) to restructure the Json format data required by data, and use it directly in legend: {data: getlegendData (name )}.

1. concatenate A Json string in the background
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, no. 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.


Related Article

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.