3

I have the following HTML code. It is working.

<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>

When I use the setCurrentRenderer javascripde mode. It gives me "no data to display".

EDIT: example source - http://www.fusioncharts.com/demos/gallery/column-and-bar/chart.asp?id=column2d_1

Mat
  • 202,337
  • 40
  • 393
  • 406
gotqn
  • 42,737
  • 46
  • 157
  • 243
  • 1
    Why are you importing jQuery **twice**?? – Pointy Apr 06 '12 at 13:28
  • I have copy this example from their site. I have delete some includes because I am not using them. This has left, but if you delete it, it gives you the same results - working without the javascript mode and not working with it. – gotqn Apr 06 '12 at 13:31

3 Answers3

4

Loading data in JavaScript from the FusionCharts website results in cross-domain errors. It is security built-in by the browser itself.

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

Try hosting the JavaScript files, Flash files and the XML data on your own local server, and it should work perfectly.

Hrishikesh Choudhari
  • 11,617
  • 18
  • 61
  • 74
0

i have used below example with javascript rendering:

<?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>


and it works fine with java script rendering..i hope this example helps

Asha Koshti
  • 2,763
  • 4
  • 22
  • 30
0

Cross domain issues can be solved by implementing CORS - cross origin resource sharing. Make sure the server that provides the data sends some extra http-headers in the response:

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

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