我被困在从 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],
['即',0.5]
所以我在文件中做错了什么请告诉我并更正我的代码database.php
。highchatr.js