Use ECharts for data chart analysis and echarts for data charts

Source: Internet
Author: User

Use ECharts for data chart analysis and echarts for data charts

I. Introduction to ECharts

JFreeChar has been used for graph analysis of statistical data. However, it is tedious and inefficient to implement coding using pure java. Later, the Fusioncharts report tool was used, it is a chart component based on Flash, uses XML as the data, and provides a wide range of Flash animations as the icon template. The simple effect is good, but flash is old and the browser needs the support of flash plug-ins, more importantly, mobile browsers basically do not support this function. Recently, Baidu provides an ECharts (Enterprise Charts) commercial product chart library. It is based on ZReader (a new lightweight canvas Class Library) and can run smoothly on PCs and mobile terminals, supports 12 types of charts, including line charts (Region charts), bar charts, scatter charts (bubble charts), line charts, and pie charts.

II. Implementation of application cases

Next we will look at the use of ECharts in combination with the application

  Case effect:

  Bar Chart

 

Switch line chart

 

View Graphic Data

 

3. How to Use ECharts
1. Establish the environment

Download echarts-2.2.2, official website address: http://echarts.baidu.com/

 

Copy the content in the build \ dist directory to the project:

 

2. Introduce the file to the sell_char.html page.

The chart directory stores 12 types of graphics js files, which can be introduced as needed. This is also officially recommended import method (modular single file Introduction)

<Head> <script src = "echarts/dist/echarts. js "> </script> <script src =" jquery/jquery-1.7.2.min.js "> </script> <script type =" text/javascript "> $ (function () {// jquery documentation ready function // path configuration require. config ({paths: {echarts: 'echarts/dist'}); require (['echarts', // represents the path set by echarts, that is, 'echarts/dist' 'echarts/chart/bar', // use a bar chart to load the bar module, and introduce bar. js 'echarts/chart/line' // load the line chart and introduce line. js file, loaded on demand], function (ec) {var myCha Rt = ec. init (document. getElementById ('prop _ data'); var option = {// configuration option, key part of using echarts ...} myChart. setOption (option) ;}); </script> 32.16sell_char.html complete code
<! -- ECharts single file introduction --> <script src = "echarts/dist/echarts. js "> </script> <script src =" jquery/jquery-1.7.2.min.js "> </script> <script type =" text/javascript "> $ (function () {// obtain the background data var category_data; // type information var soft_data; // The sales data of the software department var net_data; // The sales data of the network Department var mobile_data; // The sales data of the mobile department $. ajax ({url: '/21-sun/echarts/EChartsDataServelt', async: false, success: function (data) {category_data = data. category; soft_data = da Ta. soft_data; net_data = data.net _ data; mobile_data = data. mobile_data ;}}) // configure the path require. config ({paths: {echarts: 'echarts/dist'}); require (['echarts', 'echarts/chart/bar ', // use a bar chart to load the bar module, and load 'echarts/chart/Line'], function (ec) {// Based on the prepared dom, initialize echarts chart var myChart = ec. init (document. getElementById ('prop _ data'); var option = {tooltip: {// prompt box, show: true when the mouse is suspended, toolbox: {// define a job Show: true, feature: {dataView: {show: true, readOnly: false}, // data information button magicType: {show: true, // display line chart, bar chart, and other switch button types: ['line', 'bar', 'stack', 'tid'] }}, legend: {// legend data: ['Software parts', 'network parts', 'mobile parts']}, xAxis: [// X axis setting {type: 'category ', // category data displayed on the X axis: category_data // ["first quarter", "second quarter", "third quarter", "fourth quarter"]}], yAxis: [// y axis setting {type: 'value' // data value displayed on the Y axis}], series: [{"name": "software department", "type": "bar", "Data": soft_data // [80,300,200,100]}, {"name": "network section", "type": "bar", "data ": net_data // [50,200,120,200] },{ "name": "mobile division", "type": "bar", "data": mobile_data // [20, 60, 30, 15]}; // load the data myChart for the echarts object. setOption (option) ;}); </script> 4. backend EChartsDataServelt code
Public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response. setContentType ("text/json; charset = UTF-8"); JSONObject jsonObj = new JSONObject (); // background data, given Data here, Map map = new HashMap (); map is not obtained from the database. put ("category", new String [] {"first quarter", "second quarter", "third quarter", "fourth quarter"}); map. put ("soft_data", new int [] {80,300,200,100}); map. put ("net_data", new int [] {50,200,120,200}); map. put ("mobile_data", new int [] {20, 60, 30, 15}); jsonObj. putAll (map); response. getWriter (). println (jsonObj. toString ());}

 

For more information, clickView Source CodeRun the test in person.

For questions or technical exchanges, please join the official QQ group: (452379712)

 

Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
The copyright of this article belongs to Yantai Jerry Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the author's consent and provide the original article connection on the article page, otherwise, you are entitled to pursue legal liability.

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.