【www.bbyears.com--js教程】
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);
%>
<script type="text/javascript" src = "js/FusionCharts.js"></script>
<script type="text/javascript" src = "js/FusionChartsExportComponent.js"></script>
The chart will appear within this DIV. This text will be replaced by the chart.
<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>
FusionCharts Export Handler Component
<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>
代码二
代码如下 <%@ 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);
%>
words" content="keyword1,keyword2,keyword3">
<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 = "
+ "formatNumberScale="0" rotateNames="0" decimals="0" "
+ "useRoundEdges="1" exportEnabled="1" exportAtClient="0" "
+ "exportAction="save" exportFileName="test" "
+ "exportDialogMessage="正在导出,请稍候..." "
+ "exportHandler="FCExporter""
+ "exportShowMenuItem="1"> " +
+ "
+ "
+ "
+ "";
var chart = new FusionCharts("${basePath}/flashChart/Column3D.swf", "myFusionExport", "450", "280", "0", "0");
chart.setDataXML(xmlData);
chart.render("myFusion"); //放置图表的DIV的ID
}
</script>