Sign in to follow this  
eagles9999

Problem with XML Dataset

Recommended Posts

Testing out XT and the simple test works fine.

 

I need to get the Combination 2 yaxis chart working. Using the sample data I expected the code below to work.

The fusioncharts.js is ok as it works in the simple example. However the code below does not work.

 

I have tried locally and also from my server.

 

Can anyone spot any error or reason why it will not work please.

 

<html>
<head>
<title>My first chart using FusionCharts Suite XT</title>
<script type="text/javascript" src="fusioncharts/fusioncharts.js"></script>
<script type="text/javascript" src="fusioncharts/themes/fusioncharts.theme.fint.js"></script>
<script type="text/javascript">
  FusionCharts.ready(function(){
    var revenueChart = new FusionCharts({
        "type": mscombidy2d",
        "renderAt": "chartContainer",
        "width": "500",
        "height": "300",
        "dataFormat": "xml",
        "dataSource":
<chart caption="Revenues and Profits" subcaption="For last year" xaxisname="Month" pyaxisname="Amount (In USD)" syaxisname="Profit %" numberprefix="$" snumbersuffix="%" syaxismaxvalue="50" theme="fint">
    <categories>
        <category label="Jan" />
        <category label="Feb" />
        <category label="Mar" />
        <category label="Apr" />
        <category label="May" />
        <category label="Jun" />
        <category label="Jul" />
        <category label="Aug" />
        <category label="Sep" />
        <category label="Oct" />
        <category label="Nov" />
        <category label="Dec" />
    </categories>
    <dataset seriesname="Revenues">
        <set value="16000" />
        <set value="20000" />
        <set value="18000" />
        <set value="19000" />
        <set value="15000" />
        <set value="21000" />
        <set value="16000" />
        <set value="20000" />
        <set value="17000" />
        <set value="22000" />
        <set value="19000" />
        <set value="23000" />
    </dataset>
    <dataset seriesname="Profits" renderas="area" showvalues="0">
        <set value="4000" />
        <set value="5000" />
        <set value="3000" />
        <set value="4000" />
        <set value="1000" />
        <set value="7000" />
        <set value="1000" />
        <set value="4000" />
        <set value="1000" />
        <set value="8000" />
        <set value="2000" />
        <set value="7000" />
    </dataset>
    <dataset seriesname="Profit %" parentyaxis="S" renderas="line" showvalues="0">
        <set value="25" />
        <set value="25" />
        <set value="16.66" />
        <set value="21.05" />
        <set value="6.66" />
        <set value="33.33" />
        <set value="6.25" />
        <set value="25" />
        <set value="5.88" />
        <set value="36.36" />
        <set value="10.52" />
        <set value="30.43" />
    </dataset>
</chart>
});
revenueChart.render();
})
 
</script>
</head>
<body>
  <div id="chartContainer">FusionCharts XT will load here!</div>
</body>
</html>

Share this post


Link to post
Share on other sites

Fixed it....

I don't understand why but I removed all the spaces and line breaks between the data in <chart></chart> and it works.

 

Why does everything between the chart tags need to be a single string?

Share this post


Link to post
Share on other sites

Hi,

 

When you are using "dataFormat" as "xml" then "dataSource" attribute expects the data to be a string as such it is assuming newline as a character and showing errors in rendering.

 

If you need to seperate the xml into different lines then you need to add a backslash at the end of each line like:

'datasource':'<chart caption="Revenues and Profits" subcaption="For last year" xaxisname="Month" pyaxisname="Amount (In USD)" syaxisname="Profit %" numberprefix="$" snumbersuffix="%" syaxismaxvalue="50" theme="fint">\
    <categories>\
        <category label="Jan" />\
        <category label="Feb" />\
    </dataset>\
    <dataset seriesname="Profit %" parentyaxis="S" renderas="line" showvalues="0">\
        <set value="25" />\
        <set value="25" />\
    </dataset>\
</chart>'

Thanks.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this