gpt4 book ai didi

php - HighCharts Basic 线不显示线

转载 作者:行者123 更新时间:2023-11-30 23:20:18 25 4
gpt4 key购买 nike

我需要创建一个基本的折线图,其中的数据存储在 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>

我哪里错了?

谢谢!

最佳答案

您可以通过以下方式解析它:

JSON.parse(obj.data);

例子:

JSON.parse("[40, 30, 31, 29, 32, 35, 24, 32, 18, 41, 42, 6]")
[40, 30, 31, 29, 32, 35, 24, 32, 18, 41, 42, 6]

关于php - HighCharts Basic 线不显示线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com