Note: the dhtmlx documentation is very unclear about ALL xml formats, not just the xml format for charts. There needs to be a page somewhere with every dhtmlx object and the accompanying xml format.
The documentation was very not clear about this, but I figured it out. Here is some information for other people who are having the same issue:
Define a chart with a data series and then add another series:
chart = new dhtmlXChart({
view: "spline", container: "chart", value: "#weight#", gradient: "falling", color: "#b9a8f9",
radius: 0, alpha: 0.5, border: true,
xAxis: {
title: "Day", lines:true,
template:function(obj){ if(obj.day % 7 == 0 || obj.day == 182) {return obj.day;} else {return "";} }
},
yAxis: {
start: 238, end: 272, step: 1, title: "Weight",
template: function(obj) { return (obj % 4 ? "": obj); }
}
});
chart.addSeries({
value:"#target#",
item:{ borderColor: "#ff3300", color: "#ff3300", radius:0.5 },
line:{ color:"#ff3300", width:1 }
});
chart.load("data.php?time=" + new Date().getTime() );
In my example, I want a data series called weight and another series called target. The Y values are set by the weight and target elements, respectively, and the X values are both set by the day element. The xAxis template definition outputs a label for every 7th X value as well as the 182nd value since that’s as high as my data will go. The result is this:
To serve the xml, the following PHP file was created:
[code]<?php
error_reporting(E_ALL ^ E_NOTICE);
require(“dbconfig.php”);
$mysqli = new mysqli($host,$user,$pass,$db);
if(mysqli_connect_errno() ) {
echo "-F- Connect Failed: " . mysqli_connect_error() . “
”;
exit();
}
$sql = “SELECT * FROM test”;
$result = $mysqli->query($sql) or die($mysqli->error.LINE);
header(‘Content-type: text/xml’);
echo(“<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n”);
echo “\n”;
if($result->num_rows > 0) {
while($row = $result->fetch_assoc() ) {
# Output the ID
echo " \n";
# Output the weight if it exists in the DB
if( isset( $row["weight"] ) ) {
echo " <weight>${row["weight"]}</weight>\n";
}
# Output the target
echo " <target>${row["target"]}</target>\n";
# Output the day
$day = $row["id"] - 1;
echo " <day>" . $day . "</day>\n";
echo " </item>\n";
}
}
echo “\n”;
mysqli_close($mysqli);
?>[/code]
The structure of the XML is:
<data>
<item id="...">
<weight>...</weight>
<target>...</target>
<day>...</day>
<item>
</data>
Adding multiple series means making additional elements as children of each item element. THAT was the unclear part.