Question

Here i am trying to test FusionCharts with Flask and i am not able to get it working while it works when its used just as plain HTML and javascript with no Python code.

layout.html

<!DOCTYPE html>
<html>
<head>
    <title>Flask Fusion</title>
    <script type="text/javascript" src="../static/fusion.js"></script>
    <script type="text/javascript" src="../static/jquery.min.js"></script>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>

index.html

{% extends 'layout.html' %}

{% block content %}
    <div id="chartContainer">FusionCharts XT will load here!</div>
    <script type="text/javascript"><!--

       var myChart = new FusionCharts( "../static/Column3D.swf",
      "myChartId", "400", "300", "0" );
      myChart.setXMLUrl("data.xml");
      myChart.render("chartContainer");

    // -->
    </script>
{% endblock %}

Directory Structure

enter image description here

I have found that data.xml file returns 404 by seeing the logs from the console which are like this

127.0.0.1 - - [12/Jan/2014 13:25:35] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /static/fusion.js HTTP/1.1" 304 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /static/jquery.min.js HTTP/1.1" 304 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /data.xml HTTP/1.1" 404 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /static/Column3D.swf HTTP/1.1" 304 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /data.xml?FCTime=261 HTTP/1.1" 404 -

But the path to data.xml is perfectly correct. I dont know why its not rendering. Please help.

Was it helpful?

Solution

The data.xml is not retrieved and put in the chart at flask-template-rendering time. When the client, that have loaded the fusion.js lib, call the chart initialization, a request is made to retrieve the resource and so it should be accessible from the client side.

data.xml is inaccessible (hence 404) from the client side (since it's in the template/ folder) and on top of that the path is wrong as you can see here:

...
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /data.xml HTTP/1.1" 404 -
127.0.0.1 - - [12/Jan/2014 13:25:35] "GET /static/Column3D.swf HTTP/1.1" 304 -
...

/static/Column3D.swf is fetched using http://whateveryour.domain/static/Column3D.swf whereas /data.xml is fetched using http://whateveryour.domain/data.xml which don't exists.

Try to put your data.xml in the static folder (after all that's a static resource more than it is a template) and to access it the same way you did with Column3D.swfand it should work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top