2012-04-06 52 views
3

我有以下的HTML代碼。這是工作。Fusion Charts setCurrentRenderer('javascript')問題

<html> 
    <head>  
    <title>My First chart using FusionCharts - Using pure JavaScript</title>  

    <script type="text/javascript" src="http://www.fusioncharts.com/lib/jquery/jquery-1.6.2.min.js"></script> 
    <script language="JavaScript" src="http://www.fusioncharts.com/lib/js/FusionCharts.js"></script> 
    <script language="JavaScript" src="http://www.fusioncharts.com/lib/js/FusionCharts.HC.js"></script> 
    <script language="JavaScript" src="http://www.fusioncharts.com/lib/js/FusionCharts.HC.Charts.js"></script> 
    <script language="JavaScript" src="http://www.fusioncharts.com/lib/js/jquery.min.js"></script> 

    </head> 
    <body>  
    <div id="chartContainer">FusionCharts will load here!</div>   
    <script type="text/javascript"> 

    //FusionCharts.setCurrentRenderer('javascript'); 
      var chartObj = new FusionCharts({ 
      swfUrl: "http://www.fusioncharts.com/demos/gallery/Charts/Column2D.swf", 
      width: "500", 
      height: "300", 
      id: 'sampleChart', 
      dataSource: "http://www.fusioncharts.com/demos/gallery/Data/Col2D1.xml", 
      dataFormat: FusionChartsDataFormats.XMLURL,   
      renderAt: 'chartContainer' 
     }).render(); 

    </script>   
    </body> 
</html> 

當我使用setCurrentRenderer javascripde模式。它給了我「沒有數據顯示」。

編輯:例如源 - 從跨域錯誤FusionCharts的網站結果在JavaScript http://www.fusioncharts.com/demos/gallery/column-and-bar/chart.asp?id=column2d_1

+1

你爲什麼要導入jQuery的** **的兩倍? – Pointy 2012-04-06 13:28:13

+0

我已經從他們的網站複製這個例子。我刪除了一些包含,因爲我沒有使用它們。這已經離開了,但如果你刪除它,它會給你相同的結果 - 在沒有javascript模式的情況下工作,並且不能使用它。 – gotqn 2012-04-06 13:31:31

回答

4

加載數據。它是瀏覽器本身內置的安全性。

XMLHttpRequest cannot load http://www.fusioncharts.com/demos/gallery/Data/Col2D1.xml. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

嘗試託管自己的本地服務器上的JavaScript文件,Flash文件和XML數據,它應該很好地工作。

+0

我已經修復了在我的java腳本代碼中加載「HardCoding」XML數據的問題。 – gotqn 2012-04-10 05:30:49

0

我用下面的例子使用JavaScript渲染:

<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Multi Series Bar 2D Chart</title> 
    <link href="../assets/ui/css/style.css" rel="stylesheet" type="text/css" /> 
    <link href="../assets/prettify/prettify.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript" src="../../Charts/jquery.min.js"></script> 
    <script type="text/javascript" src="../../Charts/FusionCharts.js"></script> 
    <script type="text/javascript" src="../assets/prettify/prettify.js"></script> 
    <script type="text/javascript" src="../assets/ui/js/json2.js"></script> 
    <script type="text/javascript" src="../assets/ui/js/lib.js" ></script> 
    <script type="text/javascript" src="../assets/ui/js/DD_belatedPNG_0.0.8a-min.js"></script>       
    <script> 
     /* select the element name, css selector, background etc */ 
     DD_belatedPNG.fix('img'); 

     /* string argument can be any CSS selector */ 
    </script> 
     <p>&nbsp;</p> 
     <P align="center"></P> 
    <![endif]--> 
</head> 
<body> 
<h3 class="chart-title">Multi Series Bar 2D Chart</h3> 
<p>&nbsp;</p> 
<script type="text/javascript" src="../Data/String/js/MSBar3D1.js" ></script> 

    <div id="chartdiv" align="center">Chart will load here</div> 
    <script type="text/javascript"> 
     alert(GALLERY_RENDERER); 
     FusionCharts.setCurrentRenderer("javascript"); 
     var chart = new FusionCharts("MSBar3D.swf", "ChartId", "560", "400", "0", "0"); 
     chart.setXMLData(dataString);   
     chart.render("chartdiv"); 
    </script> 
     <p>&nbsp;</p> 
     <p align="center">3D Bar chart showing sales comparison of 5 countries across 3 years. Click on a legend item to show/hide the data series.</p> 


,它正常工作與Java腳本rendering..i希望這個例子可以幫助

0

十字域名問題可以通過實施CORS - 跨域資源共享來解決。確保服務器提供在響應發送一些額外的HTTP報頭中的數據:

Access-Control-Allow-Origin: http://the_url_that_hosts_the_page 

Access-Control-Allow-Headers: If-Modified-Since