gpt4 book ai didi

javascript - 动态数据处理之Highcharts问题

转载 作者:行者123 更新时间:2023-11-30 19:31:59 25 4
gpt4 key购买 nike

我正在使用 API highcharts 按国家/地区显示我网站的访问者数量。我通过 mysql 接收数据,我在 php 中有这个表:

<?php $data = Array ( [0] => Array ( [name] => DE [y] => 1 ) [1] => Array ( [name] => FR [y] => 3 ) [2] => Array ( [name] => US [y] => 1 ) [3] => Array ( [name] => XX [y] => 1 ) ); ?>

然后在我的 php 文件的底部,我把我的 js:

var g_donnes = '<?php echo json_encode($data); ?>';
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: g_donnes
}]
});

所以当我创建一个 console.log (g_donnes) 时,我有这个表 [{"name":"DE","y":1},{"name":"FR","y ":3},{"name":"US","y":1},{"name":"XX","y":1}],但是缺点 g_donnes 没有被数据级别的代码:g_donnes

谢谢你的帮助

最佳答案

你不需要引号:

var g_donnes = <?php echo json_encode($data); ?>;

使用引号,您的 g_donnes字符串,而不是您的代码所需的数组

关于javascript - 动态数据处理之Highcharts问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56339881/

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