使用java匯出fusioncharts 圖片2種方式

來源:互聯網
上載者:User

fusioncharts 圖片2種方式匯出:

百度網盤下載demo:

連結:pan.baidu.com/s/1jGGAOrO   密碼:7a6y

提供伺服器儲存 和 用戶端儲存

test.jsp 和 test.html是用戶端儲存

index.jsp是伺服器端儲存(請參見fusioncharts_export.properties)

請在服務端運行程式!!切記

代碼如下圖所示

 代碼如下 複製代碼

<%@ 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 should 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>

 

代碼二

 

 代碼如下 複製代碼
<%@ 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 + " could not be saved on server. There was an error. Description : " + objRtn.statusMessage);  
       }  
    }  
    //匯出圖片調用的方法  
    function startExport()
    { 
         var chart = getChartFromId("myFusionExport");   //產生的FusionCharts圖表本身的標識
         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='按地市統計<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=" 報表" target="_blank">報表</a>-不達標數' xAxisName='地市' "
                   + "yAxisName='' showToolTip='0' showValues='1' "
                   + "formatNumberScale='0' rotateNames='0' decimals='0' "
                   + "useRoundEdges='1' exportEnabled='1' exportAtClient='0' " 
                   + "exportAction='save' exportFileName='test' "
                   + "exportDialogMessage='正在匯出,請稍候...' "
                   + "exportHandler='FCExporter'"
                   + "exportShowMenuItem='1'> " +  
                   + "<set name='Jan' value='462' color='AFD8F8' /> "
                   + "<set name='Feb' value='857' color='F6BD0F' /> "
                   + "<set name='Mar' value='671' color='8BBA00' /> "
                   + "</chart>";  
        var chart = new FusionCharts("${basePath}/flashChart/Column3D.swf", "myFusionExport", "450", "280", "0", "0");  
        chart.setDataXML(xmlData);  
        chart.render("myFusion");  //放置圖表的DIV的ID  
     }    
    </script>
  </head>
  <body>
       <input type='button' value='產生FusionCharts圖表' onClick="javascript:showFusionCharts();" /> 
     <input type='button' value='匯出FusionCharts圖片' onClick="javascript:startExport();"/>
     <div id="myFusion"></div> 
  </body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.