我需要创建一个基本折线图,其中存储在 mysql db 和 php 中的数据用于数据提取,但不在图表上显示线条。
我包括以下代码:
js代码
$(document).ready(function() {
var options = {
chart: {
renderTo: 'chartPersonale',
type: 'line',
shadow: true,
marginRight: 130,
marginBottom: 25,
backgroundColor: {
linearGradient: [0, 0, 500, 500],
stops: [
[0, '#E0C6A5'],
[1, '#FDEBC4']
]
},
plotBackgroundColor: null,
plotShadow: true,
},
title: {
text: 'Performance Staff',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic']
},
yAxis: {
title: {
text: 'Appuntamenti (%)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ' %'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
};
$.ajax({ url: "Model/lineChartPersonale.php",
type: "POST",
data: "",
success: function(data) {
$.each(data, function(key,value) {
var series = { data: []};
$.each(value, function(key,val) {
if (key == 'name') {
series.name = val;
}
else
{
series.data = val
}
});
options.series.push(series);
});
console.log(options.series);
var chart = new Highcharts.Chart(options);
},
error: function(response, error) {
//
}
});
});
php代码
<?php
include('../Include/classi.inc.php');
header("content-type: application/json");
$output = array();
$db= new cDB();
$db->query("select name from staff");
while($rec=$db->record()){
$arr = array("name"=>$rec['name'],"data"=>"[".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50).", ".rand(0,50)."]");
array_push($output, json_encode($arr));
}
echo "[";
foreach($output as $val){
if(empty($val)) continue;
echo $val;
if($val != end($output)) echo ",\n";
}
echo "]";
?>
输出 PHP
[{"name":"FRANCESCA ","data":"[40, 30, 31, 29, 32, 35, 24, 32, 18, 41, 42, 6]"},
{"name":"LUIZA ","data":"[28, 34, 1, 26, 16, 24, 45, 40, 13, 48, 40, 20]"},
{"name":"ANTONELLA ","data":"[22, 16, 27, 16, 24, 14, 25, 1, 23, 4, 26, 24]"},
{"name":"CHIARA ","data":"[49, 22, 47, 7, 5, 27, 29, 50, 24, 6, 41, 25]"},
{"name":"EMILIA","data":"[8, 21, 24, 32, 39, 6, 46, 43, 19, 24, 49, 6]"},
{"name":"MARISA","data":"[29, 9, 49, 48, 24, 23, 40, 12, 33, 2, 37, 26]"}]
和 HTML
<div class="ui-grid-solo">
<div class="ui-block-a">
<div id="chartPersonale" style="min-width: 350px; height: 400px; margin: 0 auto"> </div>
</div>
</div>
我哪里错了?
谢谢!