DWR (AJAX) + Highcharts graph, pie chart, dwrhighcharts

Source: Internet
Author: User

DWR (AJAX) + Highcharts graph, pie chart, dwrhighcharts

Basic requirements:
1. The front-end will use the DWR framework (or AJAX) to call the Java background code to obtain the data to be displayed in Hightcharts.
2. Understand the JSON (JavaScript Object Notation) Format
3. Bind x and Y axes of Hightcharts
4. Use custom styles of Hightcharts
The Highcharts code (or the Highcharts configuration) is a json string. To put it bluntly, if you want to use the Hightcharts ing plug-in on the foreground, the Data Type returned by the background must be a json string.
The following uses the DWR framework as an example to draw a curve (x, Y axis) and a pie chart (without the x axis) to demonstrate how to bind background data to the x and Y axes of Highcharts. If you do not want to explain it, first map it to see the effect:

Example 1: Graph

1) JAVA background code:

2) Front-end DWR call:

Please check out what alert is...

3) configure a Hightcharts graph (define a Hightchars), var gline ={}; Nima: Which one looks like is JSON
Because Hightcharts depends on Jquery, jquery-1.8.3.min.js must be introduced, and highcharts core highcharts. js

<script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script><script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/4.0.1/highcharts.js"></script>


4) A Highcharts graph has been defined above, and now the data is bound to x, and the Y axis is displayed.
(Continue to complete the code)

Note: Use of the eval function !!!!

Example 2: Pie Chart

1) JAVA background code:

2) Front-end DWR call:

Please check out what alert is...

3) configure a Hightcharts pie chart:, var dpie = {};

4) bind data
Dpie. series [0]. data = eval (data );
New Highcharts. Chart (dpie );

Ii. Use custom styles of Hightcharts

Apply the style to all Highcharts:
Highcharts. setOptions (myTheam); // set the topic style for the chart
If you want to apply different styles to each graph, write Highcharts. setOptions (myTheam) in the background data method called by each DWR. The following two themes are defined: myTheam and myTheam1.

DWR (AJAX) + Highcharts ...) Summary V2.0
Improvement step 1): After learning to use DWR (AJAX) in j2ee, sometimes the data returned from the client from the server is an object, and it is easy to put together the json string manually, du Niang knows the json-lib class library to easily support conversion of objects to json strings in java.
Dependent Class Library: json-lib-2.4-jdk15.jar
Ezmorph-1.0.6.jar
Commons-logging.jar
Commons-lang.jar
Commons-collections.jar Basic Requirements:
1. The front-end will use the DWR framework (or AJAX) to call the Java background code to obtain the data to be displayed in Hightcharts.
2. Understand the JSON (JavaScript Object Notation) Format
3. Bind x and Y axes of Hightcharts
4. Use custom styles of Hightcharts
The Highcharts code (or the Highcharts configuration) is a json string. To put it bluntly, if you want to use the Hightcharts ing plug-in on the foreground, the Data Type returned by the background must be a json string.
The following uses the DWR framework as an example to draw a curve (x, Y axis) and a pie chart (without the x axis) to demonstrate how to bind background data to the x and Y axes of Highcharts. If you do not want to explain it, first map it to see the effect:

Example 1: Graph

1) JAVA background code:

2) Front-end DWR call:

3) JsonConveterUtil: Json converter tool class

Tool and source code download: http://pan.baidu.com/s/1mgxHExa

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.