Highcharts上有多个xAxis

时间:2014-08-26 18:37:52

标签: jquery charts highcharts

I am trying to implement attached chart using Highcharts. I have been able to plot bars with Lines on my chart. But I am unable to plot multiple xAxis with Dates and Group by Months. has any one implemented such chart. Please help

我正在尝试使用Highcharts实现附加图表。我已经能够在我的图表上绘制带有线条的条形图。但我无法使用Dates和Group by Months绘制多个xAxis。有任何人实施这样的图表。请帮忙

2 个答案:

答案 0 :(得分:2)

实际上,您可以使用两个xAx,就像这样:http://jsfiddle.net/21g0hfo1/1/

    xAxis: [{
        type: 'datetime',
        labels: {
            formatter: function () {
                return Highcharts.dateFormat("%e", this.value);
            }
        }
    }, {
        linkedTo: 0,
        type: 'datetime',
        tickLength: 0,
        lineWidth: 0,
        tickInterval: 30 * 24 * 3600 * 1000,
        labels: {
            formatter: function () {
                return Highcharts.dateFormat("%b %e", this.value);
            }
        }
    }],

我刚刚将第二个xAxis连接到第一个xAxis,每个xAxis都有不同的标签格式化程序。

答案 1 :(得分:1)

我不确定您需要多个xAxis,而是一个刻度标签格式化程序,它会在每个月的开头更改标签:

var lastMonth = null;    
$('#container').highcharts({
    xAxis: {
        type: 'datetime', 
        labels: {
            formatter: function () {
                var thisMonth = Highcharts.dateFormat("%b", this.value);
                if (lastMonth != thisMonth){
                    lastMonth = thisMonth;
                    return Highcharts.dateFormat("%b %e", this.value);
                } else {
                    return Highcharts.dateFormat("%e", this.value);
                }
            }
        }
    },
    ....

生成这样的轴(小提琴here):

enter image description here