我有3列:week, office_a, office_b
。我想使用聚集的柱状图并排比较每周有多少雇员去每个办公室。我的代码不起作用,我不知道哪一部分不正确。抱歉,对于大多数专家来说,这很简单,我是脚本编写的新手。感谢所有帮助。
我已经在StackOverflow中检查了主题,但是我看到的是y轴和x轴的硬编码数字。我正在看的是一个如何使用PHP代码对类别进行编码的示例,其中直接从MySQL数据库获取数据。我已经看到了一个示例,该示例就是我的代码中所包含的内容,只是将其替换为SQL数据,但是当我运行该代码时,它没有显示任何内容。由于能够创建表,因此正在与服务器建立连接,因此我认为这不是连接问题。
<html>
<head>
<title>Employee Head Count</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
<?php
include "config.php";
$result = mysqli_query($sqlquery);
$weeks = array();
$count_a = array();
$count_b = array();
while ($row = mysqli_fetch_array($result)) {
$weeks[] = $row['week'];
$count_a[] = $row['office_a'];
$count_b[] = $row['office_b'];
}
?>
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
margin: [ 50, 50, 100, 80]
},
title: {
text: 'Weekly Attendance'
},
credits: {
enabled: false
},
xAxis: {
categories: [<?php echo join($weeks, ','); ?>],
labels: {
rotation: -45,
align: 'right',
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Employee Count'
}
},
legend: {
enabled: false,
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 50,
y: 35,
floating: true,
shadow: true
},
tooltip: {
pointFormat: '<b>{point.y:.1f} tickets</b>',
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Week',
data: [<?php echo join($count_a, ','); ?>],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif',
textShadow: '0 0 3px black'
}
}
}]
});
});
</script>
</body>
</html>
^
emp的编号|
|
| ------------->
周