我正在尝试在fusioncharts中构建堆叠图表。 在此图表中,我想显示某个类别中每个品牌的已售产品。
我正在尝试像following
那样构建xml布局不介意sql,我得到了正确的结果。
但只有几周显示正确,我想也许阵列品牌出错了。
function graphnew($caption,$width,$height,$id,$pdo,$select,$zoeken){
$stm = $pdo->prepare("SELECT DISTINCT `datum` FROM `weeks` GROUP BY `datum` ");
$result0 = $stm->execute();
$results0 = $stm->fetchAll(PDO::FETCH_ASSOC);
$stm3 = $pdo->prepare("SELECT DISTINCT brand FROM `weeks` WHERE `".$select."` = '".$zoeken."'");
$result = $stm3->execute();
$results = $stm3->fetchAll(PDO::FETCH_ASSOC);
$stm4 = $pdo->prepare("SELECT SUM(`sales`) AS 'sales' FROM `weeks` WHERE `".$select."` = '".$zoeken."' GROUP by `brand`,`datum` ");
$result1 = $stm4->execute();
$results1 = $stm4->fetchAll(PDO::FETCH_ASSOC);
$arrData = array(
"chart" => array(
"caption" => "$caption",
"xAxisName"=> "Dagen",
"yAxisName"=> "aantal",
"numberPrefix"=>"",
"showValues" => "0",
"lineThickness"=> "2",
"displayValue" => "aantal",
"theme" => "zune",
"xAxisLineThickness"=> "3"
)
);
$datum=array();
$brands=array();
$sales=array();
// Push the data into the array
foreach($results0 as $row) {
array_push($datum, array(
"label" => $row["datum"]
)
);
}
foreach($results1 as $row) {
array_push($sales, array(
"value" => $row["sales"]
)
);
}
foreach($results as $row) {
array_push($brands, array(
"seriesName" => $row["brand"],
)
);
}
$arrData["categories"]= array(array("category"=> $datum));
$arrData["dataset"] = array(array("seriesName"=> $brands, "data"=>$sales));
// Translate to json
$jsonEncodedData = json_encode($arrData);
/**
* Creates a `columnChart` chart object using the FusionCharts PHP class constructor.
* Syntax for the constructor: `FusionCharts("type of * chart", "unique chart id", "width of chart",
* "height of chart", "div id to render the chart", "data format", "data source")`
*/
$columnChart = new FusionCharts("stackedcolumn2d", "myFirstChart3" , $width, $height, $id, "json", $jsonEncodedData);
// Render the chart
$columnChart->render();
}