gpt4 book ai didi

php - 尝试使用 PHP 从 MySQL 数据库获取数据时,HighCharts 饼图 X 轴值不显示

转载 作者:行者123 更新时间:2023-11-29 14:08:23 24 4
gpt4 key购买 nike

我陷入了从 mysql 数据库到 HighCharts 的数据连接

highchart.js代码如下

            <script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container5',
plotBackgroundColor: null,
plotBorderWidth: 2,
plotShadow: false
},
title: {
text: '<p><?php echo $chart5; ?></p>'
},
// tooltip: {
// pointFormat: '{series.name}: <b>{point.percentage}%</b>',
// percentageDecimals: 1
// },
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},


xAxis: {
categories: [<?php echo "'".implode("','",$data)."'"; ?>]
},
series: [{
type: 'pie',
data: [<?php echo implode(",",$data1); ?>]

}]
});
});

});

</script>

和我的database.php:

            $data = array();
$sql = "SELECT x_axis FROM licence_chart ";
$result9 = mysql_query($sql);
$data9 = array();
while ($row = mysql_fetch_array($result9)) {
$data9 = $row['x_axis'];
$data[] = $data9;
}

$data1 = array();
$sql = "SELECT y_axis FROM licence_chart ";
$result10 = mysql_query($sql);
$data10 = array();
while ($row = mysql_fetch_array($result10)) {
$data10 = $row['y_axis'];
$data1[] = $data10;
}

echo "'".join("','",$data)."'";
echo join(",",$data1);

当我在本地主机中运行此代码时,会显示饼图,但在 x 轴 中不显示值该值显示为 Slice 。但是 y 轴 值显示正确,

licence_chart 表数据中,x_axies 中的 y_axies 是列

x_axies{crome,opera,ie,firefox,safari}
y_axies{0.12,0.23,23.2,56.2,2}

我想要在data[]中的highchart.js文件中数据会像这样

['safari',10], ['firefox',1.5],['ie',0.5]

所以我在 database.phphighchatr.js 文件中做错了什么,请告诉我并更正我的代码。

最佳答案

上述问题的正确答案,我正在使用它并获得上述格式

<php
$sql = "SELECT x_axis,y_axis FROM licence_chart ";
$result9 = mysql_query($sql);
$data9 = array();
while ($row = mysql_fetch_array($result9))
{
$data9 = "'".$row['x_axis']."'".",".$row['y_axis'];
$data[] = $data9;
}
for($ii=0;$ii<count($data);$ii++)
{
echo "[".$data[$ii]."]," ;
}
?>

关于php - 尝试使用 PHP 从 MySQL 数据库获取数据时,HighCharts 饼图 X 轴值不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13954081/

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