Converting a php array into something that can be used

I have data in a MySQL database that I’ll need to run some calculations on before a resultant php array is arrived at. I’m struggling to find an example of how I convert this array into a usable array for charts. Even using the json encode it doesn’t appear to output in a\ usable form. One problem is I’m very inexperienced in Javascript. Do you have any example code I can look at that goes from extracting data from MySQL, forming an array and converting the php array into something that can be used in the exampe charts you have set up. I think this will provide a big step in my gap in knowledge.

Kind regards


You need to use Connector: … ctor:start
You can use the same Connector as in samples with DataView. I.e. like here: dataview/01_static_loading.html

Or you can use your custom script in chart.load(“some.php”,“json”), where some.php generates json for chart.

So here is what I have so far. The MySQL table is 3 columns, id, Country Name and ‘data’ = an integer. I’m getting nothing in the 3D pie chart. Any ideas?

<?php require("codebase/connector/data_connector.php"); $res=mysql_connect("localhost","user","pswd"); mysql_select_db("table"); $phpArray = "SELECT id, Country, Data FROM table"; $result = mysql_query($phpArray); while($row = mysql_fetch_assoc($result)) { $dataset1[] = array($row['Country'],$row['Data']); } ?>

if you are using “#data#” and “#Country#” templates, the datasource should contain these properties for each item. For example as in:

{id: 1, Country: “France”, data: 20},


So, the php script should be changed:

$dataset1[] = array(“Country” => $row[‘Country’], “data” => $row[‘Data’]);

If you leave php script as is, you should modify chart configuration:

var chart = new dhtmlXChart({


Here is an example: