Use java to export fusioncharts images in two ways

Source: Internet
Author: User

Fusioncharts Image export methods:

Baidu online storage download demo:

Link: pan.baidu.com/s/1jGGAOrO password: 7a6y

Server saving and client saving

Test. jsp and test.html are saved by the client

Index. jsp is saved on the server (see fusioncharts_export.properties)

Run the program on the server !! Remember

The code is shown in the following figure.

The code is as follows: Copy code

<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
Request. setAttribute ("basePath", basePath );
%>
<Html>
<Head>
<Script type = "text/javascript" src = "js/FusionCharts. js"> </script>
<Script type = "text/javascript" src = "js/FusionChartsExportComponent. js"> </script>
</Head>
<Body bgcolor = "# ffffff">
<Div id = "chartdiv" align = "center"> The chart will appear within this DIV. This text will be replaced by the chart. </div>
<Script type = "text/javascript">
// Create the chart.
// Note that you necessarily need to set the registerWithJS attribute as 1, as JavaScript is used for client-
// Side communication between the chart and FusionCharts Exporter Component.
Var myChart = new FusionCharts ("flashChart/Column3D.swf", "myChartId", "500", "300", "0", "1 ");
MyChart. setXMLUrl ("SimpleExample. xml ");
MyChart. render ("chartdiv ");
</Script>
<! -- We also create a DIV to contain the FusionCharts client-side exporter component -->
<Div id = "fcexpDiv" align = "center"> FusionCharts Export Handler Component </div>
<Script type = "text/javascript">
// Render the export component in this
// Note: fcExporter1 is the dom id of the DIV and shocould be specified as value of exportHandler
// Attribute of chart XML.
Var myExportComponent = new FusionChartsExportObject ("fcExporter1", "flashChart/FCExporter.swf ");
// Render the exporter SWF in our DIV fcexpDiv
MyExportComponent. Render ("fcexpDiv ");
</Script>
</Body>
</Html>

 

Code 2

 

The code is as follows: Copy code
<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
Request. setAttribute ("basePath", basePath );
%>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Base href = "<% = basePath %>">
    
<Title> My JSP 'index. jsp 'starting page </title>
<Meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "This is my page">
<! --
<Link rel = "stylesheet" type = "text/css" href = "styles.css">
-->
<Script type = "text/javascript" src = "$ {basePath}/js/FusionCharts. js"> </script>
<Script type = "text/javascript" src = "$ {basepath}/js/FusionChartsExportComponent. js"> </script>
<Script type = "text/javascript">
Function FC_Exported (objRtn)
    {    
If (objRtn. statusCode = "1 ")
       {  
Alert ("The chart with DOM Id" + objRtn. DOMId + "was successfully saved on server. The file can be accessed from" + objRtn. fileName );
       }
Else
       {  
Alert ("The chart with DOM Id" + objRtn. DOMId + "cocould not be saved on server. There was an error. Description:" + objRtn. statusMessage );
       }  
    }  
// Call method for exporting images
Function startExport ()
    { 
Var chart = getChartFromId ("myFusionExport"); // ID of the generated FusionCharts chart
If (chart. hasRendered ())
         {  
Chart. exportChart ();
         }
Else
         {  
Alert ("Please wait for the chart to finish rendering, before you can invoke exporting ");
         }
    }
Function showFusionCharts ()
    {   
Var xmlData = "<chart palette = '2' caption = 'by City statistics <a href =" http://www.suchso.com/catalog.asp? Tags = html5 % E6 % 8A % A5 % E8 % A1 % A8 % E6 % 8F % 92% E4 % BB % B6 "class =" keylink "title =" report "target =" _ blank "> Report </a>-number of non-compliant cities 'xaxisname = 'prefecture-City City '"
+ "YAxisName = ''showtooltip = '0' showValues = '1 '"
+ "FormatNumberScale = '0' rotateNames = '0' decimals = '0 '"
+ "UseRoundEdges = '1' exportEnabled = '1' exportAtClient = '0 '"
+ "ExportAction = 'save' exportFileName = 'test '"
+ "ExportDialogMessage = 'exporting ...'"
+ "ExportHandler = 'fcexporter '"
+ "ExportShowMenuItem = '1'>" +
+ "<Set name = 'Jan 'value = '000000' color = 'afd8f8'/>"
+ "<Set name = 'Feb' value = '000000' color = 'f6bd0f'/>"
+ "<Set name = 'mar' value = '000000' color = '8bba00'/>"
+ "</Chart> ";
Var chart = new FusionCharts ("$ {basePath}/flashChart/Column3D.swf", "myFusionExport", "450", "280", "0", "0 ");
Chart. setDataXML (xmlData );
Chart. render ("myFusion"); // ID of the DIV where the chart is placed
     }    
</Script>
</Head>
<Body>
<Input type = 'Button 'value = 'generate the FusionCharts chart 'onclick = "javascript: showFusionCharts ();"/>
<Input type = 'Button 'value = 'export FusionCharts Image 'onclick = "javascript: startExport ();"/>
<Div id = "myFusion"> </div>
</Body>
</Html>

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.