1. First, let's take a look at the page for performance: MyChart. jsp <% @ page Language = "Java" contenttype = "text/html; charset = UTF-8"
Pageencoding = "UTF-8" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<Head>
<Title> fusion chart test </title>
<LINK rel = "stylesheet" href = "../contents/style.css" type = "text/CSS"/>
<SCRIPT src = "../JS/jquery. js" type = "text/JavaScript"> </SCRIPT>
<Script language = "JavaScript" src = "../JS/fusioncharts. js"> </SCRIPT> <SCRIPT type = "text/JavaScript">
$ (Document). Ready (function (){
// Do something here
$. Ajax ({
Type: "Post ",
URL: "../test", // The Request Path request action (inheriting the login method in dispatcheraction)
Success: function (responsetext ){
// Alert (responsetext );
// Configure
VaR chart = new fusioncharts ("../charts/fcf_line.swf", "chartid", "600", "350 ");
Chart. setdataxml (responsetext );
Chart. Render ("chartdiv ");
}
});
});
</SCRIPT>
</Head>
<Body bgcolor = "# ffffff">
<Div align = "center"> fusion charts free </div>
<Div id = "chartdiv" align = "center"> </div>
</Body>
</Html> Note: The JS and CSSS of the parent file, such as jquery.js, fusioncharts.js, style.css, and charts folders, which can be found in the downloaded fusionchartsfree file. If you just want to read data from XML, it's easy. Refer to the relevant example here. 2. Let's take a look at the format of the data returned in the background: servlet. javapackage servlet; import java. Io. ioexception; import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse ;/**
* @ Title: servlet. Java
* @ Package Servlet
* @ Description:
* @ Author lzh
* @ Date Dec 2, 2011 2:44:51
* @ Version V1.0
*/
Public class servlet extends httpservlet {
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
This. dopost (request, response );
}
Public void dopost (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Request. setcharacterencoding ("GBK ");
Stringbuffer sb = new stringbuffer ();
SB. append ("<graph caption = 'monthly unit sale' xaxisname = 'month' yaxisname = 'unit' shownames = '1' decimalprecision = '2' formatnumberscale = '0'> ");
SB. append ("<set name = '20180101' value = '20180101' color = 'ccffff' hovertext = '20180101' link = 'HTTP: // www.baidu.com '/> ");
SB. append ("<set name = '20180101' value = '20180101' color = 'f6bd0f'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '8bba00'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = 'ff8e46'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '008e8e'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = 'd64646 '/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '8e468e '/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '20180101'/> ");
SB. append ("<set name = '2013' value = '000000' color = 'b3aa00'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '008ed6 '/> ");
SB. append ("<set name = '20180101' value = '20180101' color = '9d080d'/> ");
SB. append ("<set name = '20180101' value = '20180101' color = 'a186be'/> ");
SB. append ("</graph> ");
Response. setcharacterencoding ("UTF-8 ");
System. Out. println (sb. tostring ());
Response. getwriter (). Print (sb. tostring ());
}
} 3. If you only want to read XML files, replace responsetext with the corresponding XML file in MyChart. The XML format is as follows: <graph caption = ''subcaption ='' hovercapbg = 'ffecaa 'hovercapborder = 'f47e00' formatnumberscale = '0' decimalprecision = '0' showvalues = '0' numdivlines = '3' numvdivlines = '0' yaxisminvalue = '000000' yaxismaxvalue = '000000' rotatenames = '0'>
<Categories>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/>
<Category name = '2017-08-17 '/> </Categories>
<Dataset seriesname = 'temperature 'color = '1d8bd1' anchorbordercolor = '1d8bd1 'anchorbgcolor = '1d8bd1'>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
</Dataset> <dataset seriesname = 'humidity 'color = 'f1683c' anchorbordercolor = 'f1683c 'anchorbgcolor = 'f1683c'>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
</Dataset> <dataset seriesname = 'precipitation 'color = '2ad62a' anchorbordercolor = '2ad62a 'anchorbgcolor = '2ad62a'>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
</Dataset> <dataset seriesname = 'visibility 'color = 'dbdc25' anchorbordercolor = 'dbdc25' anchorbgcolor = 'dbdc25'>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
<Set value = '000000'/>
</Dataset>
</Graph>
Examples of using fusionchartsfree for pie charts, bar charts, and line charts