【发布时间】:2025-12-17 15:50:01
【问题描述】:
我卡在从 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);
当我在 localhost 中运行此代码时,饼图会显示,但在 x-axies 中未显示值
该值显示为Slice 。但y-axies 值显示正确,
在licence_chart 表中这样的数据在表x_axies 中,y_axies 是列
x_axies{crome,opera,ie,firefox,safari}
y_axies{0.12,0.23,23.2,56.2,2}
我想要在highchart.js 中的文件data[]
数据会是这样的
['safari',10],['firefox',1.5],['ie',0.5]
所以我在database.php 和highchatr.js 文件中做错了什么请告诉我并更正我的代码。
【问题讨论】:
-
该错误意味着您将字符串作为 Xvalue 传递。我会看看你是如何解析 PHP 中的 x 和 y 值的。
-
所有的连接是什么?
标签: php mysql html extjs4 highcharts