【发布时间】:2015-09-04 20:22:03
【问题描述】:
我正在编写一个显示条形图的脚本。我有这个工作到一定程度。
我要做的是在图表中显示 MySQL 查询的结果,左侧为负值,右侧为正值。表中的结果值为“1”或“2”。
目前的代码是:
$(function () {
var data =[<?php
mysql_select_db($database_test, $con);
$query_result = sprintf("SELECT COUNT(Condition), ConditionValue AS RC1 FROM FeedBack WHERE ConditionValue = 1 AND FeedBackDate BETWEEN '" . date("Y-m-d", strtotime($_POST['FromDate'])) . "' AND '". date("Y-m-d", strtotime($_POST['ToDate'])) . "'");
$result = mysql_query($query_result, $con) or die(mysql_error());
$totalRows_result_rc = mysql_num_rows($result);
while ($row_result = mysql_fetch_assoc($result)){
?>
[<?php echo $row_result['RC1'];?>]
<?php
}
?>
]
$('#container1').highcharts({
chart: {
type: 'bar'
},
title: {
text: 'Condition'
},
subtitle: {
text: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -20,
y: 34,
floating: false,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
plotOptions: {
series: {
shadow:false,
borderWidth:0,
dataLabels:{
enabled:true,
formatter: function() {
return this.y +'%';
}
}
}
},
xAxis:{
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickLength:3,
title:{
text:'<?php print $totalRows_result_rc;?> records'
},
},
yAxis:{
lineColor:'#999',
lineWidth:1,
tickColor:'#666',
tickWidth:1,
tickLength:3,
gridLineColor:'#ddd',
title:{
text:'Between <?php print $_POST['FromDate'];?> and <?php print $_POST['ToDate'];?>',
rotation:0,
margin:50,
},
labels: {
formatter: function() {
return (this.isLast ? this.value + '%' : this.value);
}
}
},
series: [{
color: '#CC0000',
name: 'Conditione',
data: data,
maxPointWidth: 10,
index:0,
legendIndex:1,
exporting: {
filename: 'Ccondition'
}
}]
});
});
我已经用多种不同的方式编写了这个,但无法获得所需的结果。
谁能指出我哪里出错了。非常感谢您花时间提供帮助。
【问题讨论】:
-
那么,什么不起作用?默认情况下,对于条形图,左侧为负值,右侧为正值。有什么更具体的,或者与您想要的默认行为不同的东西吗?
-
另外,你说的值要么是1,要么是2。你的意思是它们也可以是-1和-2?
标签: highcharts