Highcharts带有正负数据的条形图

Highcharts带有正负数据的条形图,highcharts,Highcharts,我正在编写一个显示条形图的脚本。我在一定程度上可以做到这一点 我试图做的是在图表中显示MySQL查询的结果,左边是负值,右边是正值。表中的结果值为1或2 到目前为止,守则是: $(function () { var data =[<?php mysql_select_db($database_test, $con); $query_result = sprintf("SELECT COUNT(Condition), ConditionValue AS RC1 FROM FeedBac

我正在编写一个显示条形图的脚本。我在一定程度上可以做到这一点

我试图做的是在图表中显示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'
}

}]
});
});
我用了很多不同的方法写了这篇文章,但是没有得到要求的结果


谁能指出我错在哪里。非常感谢您花时间提供帮助。

这可以通过使用两个系列来完成:一个包含负值,另一个包含正值。根据您的需要,它们应该(但不是必需的)共享相同的xAxis值。看看highcharts网站上的这个。注意使用两个系列:

    series: [{
        name: 'Male',
        data: [-2.2, -2.2, -2.3, -2.5, -2.7, -3.1, -3.2,
            -3.0, -3.2, -4.3, -4.4, -3.6, -3.1, -2.4,
            -2.5, -2.3, -1.2, -0.6, -0.2, -0.0, -0.0]
    }, {
        name: 'Female',
        data: [2.1, 2.0, 2.2, 2.4, 2.6, 3.0, 3.1, 2.9,
            3.1, 4.1, 4.3, 3.6, 3.4, 2.6, 2.9, 2.9,
            1.8, 1.2, 0.6, 0.1, 0.0]
    }]
和链接到相同的类别:

var categories = ['0-4', '5-9', '10-14', '15-19',
        '20-24', '25-29', '30-34', '35-39', '40-44',
        '45-49', '50-54', '55-59', '60-64', '65-69',
        '70-74', '75-79', '80-84', '85-89', '90-94',
        '95-99', '100 + '];

他们在这里进行一些格式化,使负值标记为正值,而其他一些yAxis标签更改。

那么,什么不起作用?默认情况下,对于条形图,负值在左侧,正值在右侧。是否有更具体的东西,或者与您想要的默认行为不同?另外,您说值为1或2。你是说它们也可以是-1和-2吗?