HighCharts中具有负值和xAxis类别的柱状图 [英] Column chart with negative values and categories on xAxis in HighCharts

查看:146
本文介绍了HighCharts中具有负值和xAxis类别的柱状图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在网络应用程序中使用了highcharts。
这里是显示柱状图中的人口统计数据的任务,如图:



我现在拥有的仅仅是下一个例子: http:// jsfiddle .net / futw5e8k / 1 /

  Highcharts.chart('container',{

图表:{
类型:'列'
},

标题:{
文本:'水果总消费量,按性别分组'
},

xAxis:{
类别:['苹果','橘子','梨','葡萄','香蕉'],
抵消:-150
},

yAxis:{
allowDecimals:false,
title:{
text:'Number of fruits'
}
},

tooltip:{
formatter:function(){
return'< b>'+ thi sx +'< / b>< br />'+
this.series.name +':'+ this.y +'< br />'+
'总计: '+ this.point.stackTotal;
}
},

plotOptions:{
列:{
堆栈:'normal'
}
},

系列:[{
名称:'John',
数据:[5,3,4,7,2],
},{
名称:'Joe',
data:[-3,-4,-4,-2,-5],
}]

});

目前在中间显示 categories 时出现问题与一些空间的图形。在我的例子中, offset 并不是根据数据生成的,所以不是所有情况下都是这样。

解决方案

您可以使用两个y轴来定义位置,使用 top height



演示: http://jsfiddle.net/futw5e8k / 2 /

Highcharts.chart('container', {图:{类型:'列'},标题:{文:'水果总消费,按性别分组'},xAxis:{类别:['苹果','桔子','梨','葡萄' Bananas'],偏移量:-150,lineWidth:0,tickWidth:0},yAxis:[{allowDecimals:false,title:{text:'Number of水果',y:100,x:-10},top:50,height:124},{title:{text:null},top:200,height:150,offset:0}],tooltip:{formatter: function(){return'< b> + this.x +'< / b>< br />'+ this.series.name +':'+ this.y +'< br /> ;'+'总计:'+ this.point.stackTotal; }},plotOptions:{column:{stacking:'normal'}},series:[{name:'John',data:[5,3,4,7,2],},{name:'Joe', yAxis:1,data:[-3,-4,-4,-2,-5],}]});

 < script src =https://code.highcharts.com/highcharts.js>< / script>< script src =https ://code.highcharts.com/modules/exporting.js>< / script>< div id =containerstyle =min-width:310px; height:400px; margin:0 auto> < / div>  


Well, I'm using highcharts in web app. Here is task to show Demographical data in column chart like on image :

What I have for now is just next example : http://jsfiddle.net/futw5e8k/1/

Highcharts.chart('container', {

chart: {
    type: 'column'
},

title: {
    text: 'Total fruit consumtion, grouped by gender'
},

xAxis: {
    categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
    offset: -150
},

yAxis: {
    allowDecimals: false,
    title: {
        text: 'Number of fruits'
    }
},

tooltip: {
    formatter: function () {
        return '<b>' + this.x + '</b><br/>' +
            this.series.name + ': ' + this.y + '<br/>' +
            'Total: ' + this.point.stackTotal;
    }
},

plotOptions: {
    column: {
        stacking: 'normal'
    }
},

series: [{
    name: 'John',
    data: [5, 3, 4, 7, 2],
}, {
    name: 'Joe',
    data: [-3, -4, -4, -2, -5],
}]

});

Currently is problem with displaying categories in middle of graph with some space. In my example offset isn't generated according to data, so isn't for all cases

解决方案

You could use two y axes that will have defined position using top and height.

Demo: http://jsfiddle.net/futw5e8k/2/

Highcharts.chart('container', {

    chart: {
        type: 'column'
    },

    title: {
        text: 'Total fruit consumtion, grouped by gender'
    },

    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
        offset: -150,
        lineWidth: 0,
        tickWidth: 0
    },

    yAxis: [{
        allowDecimals: false,
        title: {
            text: 'Number of fruits',
            y: 100,
            x: -10
        },
        top: 50,
        height: 124
    },{
    		title: {
        	text: null
        },
        top: 200,
        height: 150,
        offset: 0
    }],

    tooltip: {
        formatter: function () {
            return '<b>' + this.x + '</b><br/>' +
                this.series.name + ': ' + this.y + '<br/>' +
                'Total: ' + this.point.stackTotal;
        }
    },

    plotOptions: {
        column: {
            stacking: 'normal'
        }
    },

    series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2],
    }, {
        name: 'Joe',
        yAxis: 1,
        data: [-3, -4, -4, -2, -5],
    }]
});

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

这篇关于HighCharts中具有负值和xAxis类别的柱状图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆