JSChart: No data loaded using json

Posted by user969261 
JSChart: No data loaded using json
October 18, 2011 10:05AM
Hi,

I tried many thing but I can't figure out what's wrong with my code.

The JS is from the example:
<script type="text/javascript">
	var myChart = new JSChart('chartcontainer', 'pie');
	myChart.setDataJSON('/statistiques/ajax/statuts');
	myChart.draw();
</script>


and the page /statistiques/ajax/statuts returns :
{
    "JSChart": {
        "datasets": {
            "type": "pie",
            "data": [
                {
                    "unit": "0",
                    "value": "0"
                },
                {
                    "unit": "1",
                    "value": "6088"
                },
                {
                    "unit": "2",
                    "value": "17"
                },
                {
                    "unit": "3",
                    "value": "4"
                },
                {
                    "unit": "4",
                    "value": "0"
                },
                {
                    "unit": "5",
                    "value": "0"
                },
                {
                    "unit": "6",
                    "value": "1"
                },
                {
                    "unit": "7",
                    "value": "7"
                },
                {
                    "unit": "8",
                    "value": "6"
                },
                {
                    "unit": "9",
                    "value": "66"
                },
                {
                    "unit": "10",
                    "value": "0"
                }
            ]
        }
    }
}

Which is valid according to [jsonlint.com] (the header even says Content-Type:application/json) and respects your schema as far as I know.

Any ideas of what could be wrong?, Why I get the message : JSChart: No data loaded?

Thanks!
Re: JSChart: No data loaded using json
October 18, 2011 11:01AM
Hi,
In some cases there can be more then one datasets so we actually expect that to be an array of objects, even if there is only one dataset used in the graph. In your case, this should work:

{
    "JSChart": {
        "datasets": [
			{
				"type": "pie",
				"data": [
					{
						"unit": "0",
						"value": "0"
					},
					{
						"unit": "1",
						"value": "6088"
					},
					{
						"unit": "2",
						"value": "17"
					},
					{
						"unit": "3",
						"value": "4"
					},
					{
						"unit": "4",
						"value": "0"
					},
					{
						"unit": "5",
						"value": "0"
					},
					{
						"unit": "6",
						"value": "1"
					},
					{
						"unit": "7",
						"value": "7"
					},
					{
						"unit": "8",
						"value": "6"
					},
					{
						"unit": "9",
						"value": "66"
					},
					{
						"unit": "10",
						"value": "0"
					}
				]
			}
		]
    }
}

Sabin

--------------------
JS Charts - Created by Smartketer LLC
Sorry, you do not have permission to post/reply in this forum.