Javascript Highcharts-当父容器较小时,在日期时间x轴上显示每个月

Javascript Highcharts-当父容器较小时,在日期时间x轴上显示每个月,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我有一张两行的海图。x轴是datetime类型 我希望在x轴上为整个日期范围内的每个月标记一个记号:7月11日、8月11日、9月11日等 如果我将父容器设置为非常宽,则显示所有月刻度的唯一方法是。但是,我的生产布局只有一个695px的容器 当我处于较小的宽度时,如何强制显示所有刻度 这是我的密码: var chart; var lineIndex = 0,splineIndex=0; $(document).ready(function() { chart = new Highchar

我有一张两行的海图。x轴是datetime类型

我希望在x轴上为整个日期范围内的每个月标记一个记号:7月11日、8月11日、9月11日等

如果我将父容器设置为非常宽,则显示所有月刻度的唯一方法是。但是,我的生产布局只有一个695px的容器

当我处于较小的宽度时,如何强制显示所有刻度

这是我的密码:

var chart;
var lineIndex = 0,splineIndex=0;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            zoomType: 'xy'
        },
        exporting: { enabled: false },
        title: {
            text: ''
        },
        legend:{
            itemStyle: {
                fontSize: '13px',
                fontFamily: 'Arial,sans-serif'
            }
        },
        xAxis: {
            type: 'datetime',
            min: Date.UTC(2011, 4, 31),
            max: Date.UTC(2012, 11, 6),
            labels: {
                step: 1,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Arial,sans-serif'
                }
            },
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%b \'%y',
                year: '%Y'
            }
        },
        yAxis: [{ // Primary yAxis
            labels: {
                style: {
                    fontSize: '13px',
                    fontFamily: 'Arial,sans-serif'
                    },
                formatter: function() {
                    return '$' + Highcharts.numberFormat(this.value,2,'.',",");
                }
            },
            title: {
                text: '',
                style: {
                    color: '#89A54E'
                },
            },
            max:.85,                
            opposite: true   
        }, { // Secondary yAxis
            gridLineWidth: 0,
            title: {
                text: ''
            },
            min:9000,
            max:12000,
            labels: {
                style: {
                    fontSize: '13px',
                    fontFamily: 'Arial,sans-serif'
                },
                formatter: function() {
                    return '$' + Highcharts.numberFormat(this.value,0,".",",");
                }
            }
        }],
        tooltip: {
            enabled: false
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true,
                    useHTML: true,
                    formatter: function() {
                        if(this.y == 10000) {
                            return '<div class="tweak">$' + Highcharts.numberFormat(Math.round(this.y),0,".",",") + '</div>';
                        } else if (this.y > 5) {
                            return '<div class="tweak-0">$' + Highcharts.numberFormat(Math.round(this.y),0,".",",") + '</div>';
                        } else if (this.x == Date.UTC(2011, 11, 1)) { // grab values for special dates and assign tweak classes so we can adjust the label spacing
                            return '<div class="tweak-1">$' + Highcharts.numberFormat(this.y,3,".",",") + '</div>';
                        } else if (this.x == Date.UTC(2012, 1, 1)) { 
                            return '<div class="tweak-2">$' + Highcharts.numberFormat(this.y,3,".",",") + '</div>';
                        } else if (this.x == Date.UTC(2011, 7, 1) || this.x == Date.UTC(2012, 7, 1) ) { 
                            return '<div class="tweak-3">$' + Highcharts.numberFormat(this.y,2,".",",") + '</div>';
                        } else if ( this.x == Date.UTC(2012, 0, 17) ) {
                            return '<div class="tweak-4">$' + Highcharts.numberFormat(this.y,3,".",",") + '</div>';
                        }
                    }}
            }
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Growth of $10,000 Investment',
            type: 'line',
            color: '#002d56',
            yAxis: 1,
            data: [
              [Date.UTC(2011, 5, 1), 10000],
              [Date.UTC(2011, 8, 1), 9996],
              [Date.UTC(2011, 11, 1), 10652],
              [Date.UTC(2012, 2, 1), 11387],
              [Date.UTC(2012, 5, 1), 11586],
              [Date.UTC(2012, 8, 1), 11984],
              [Date.UTC(2012, 11, 1), 12179]
            ]
        }, {
            name: 'Historical Distributions Per Share',
            color: '#762123',
            type: 'line',
            enableMouseTracking: false,
            data: [
                [Date.UTC(2011, 5, 1), 0.70],
                [Date.UTC(2011, 6, 1), 0.70],
                [Date.UTC(2011, 7, 1), 0.70],
                [Date.UTC(2011, 8, 1), 0.70],
                [Date.UTC(2011, 9, 1), 0.70],
                [Date.UTC(2011, 9, 25), 0.70],
                [Date.UTC(2011, 10, 1), 0.717],
                [Date.UTC(2011, 11, 1), 0.717],
                [Date.UTC(2012, 0, 10), 0.717],
                [Date.UTC(2012, 0, 17), 0.728],
                [Date.UTC(2012, 0, 24), 0.728],
                [Date.UTC(2012, 0, 31), 0.745],
                [Date.UTC(2012, 1, 1), 0.745],
                [Date.UTC(2012, 1, 28), 0.745],
                [Date.UTC(2012, 2, 6), 0.76],
                [Date.UTC(2012, 2, 13), 0.76],
                [Date.UTC(2012, 2, 20), 0.76], 
                [Date.UTC(2012, 2, 27), 0.76], 
                [Date.UTC(2012, 3, 3), 0.76], 
                [Date.UTC(2012, 3, 10), 0.76],
                [Date.UTC(2012, 3, 17), 0.76], 
                [Date.UTC(2012, 3, 24), 0.76], 
                [Date.UTC(2012, 4, 1), 0.76], 
                [Date.UTC(2012, 4, 8), 0.76], 
                [Date.UTC(2012, 4, 15), 0.76], 
                [Date.UTC(2012, 4, 22), 0.76], 
                [Date.UTC(2012, 4, 29), 0.76], 
                [Date.UTC(2012, 5, 5), 0.76], 
                [Date.UTC(2012, 5, 12), 0.76], 
                [Date.UTC(2012, 5, 19), 0.76], 
                [Date.UTC(2012, 5, 26), 0.76], 
                [Date.UTC(2012, 6, 3), 0.76], 
                [Date.UTC(2012, 6, 10), 0.76], 
                [Date.UTC(2012, 6, 17), 0.76], 
                [Date.UTC(2012, 6, 24), 0.76], 
                [Date.UTC(2012, 6, 31), 0.76],
                [Date.UTC(2012, 7, 1), 0.76],
                [Date.UTC(2012, 7, 7), 0.76], 
                [Date.UTC(2012, 7, 14), 0.76], 
                [Date.UTC(2012, 7, 21), 0.76], 
                [Date.UTC(2012, 7, 28), 0.76], 
                [Date.UTC(2012, 8, 4), 0.76], 
                [Date.UTC(2012, 8, 11), 0.76], 
                [Date.UTC(2012, 8, 18), 0.76], 
                [Date.UTC(2012, 8, 25), 0.76],
                [Date.UTC(2012, 11, 1), 0.76]    
            ],
            marker: {
                enabled: false
            }
        }]
    });
});
var图;
var lineIndex=0,splineIndex=0;
$(文档).ready(函数(){
图表=新的高点图表。图表({
图表:{
renderTo:'容器',
zoomType:'xy'
},
正在导出:{enabled:false},
标题:{
文本:“”
},
图例:{
项目样式:{
fontSize:'13px',
字体系列:“Arial,无衬线”
}
},
xAxis:{
键入:“日期时间”,
最小值:UTC日期(2011年4月31日),
最大值:UTC日期(2012年11月6日),
标签:{
步骤:1,
风格:{
fontSize:'13px',
字体系列:“Arial,无衬线”
}
},
dateTimeLabelFormats:{//不显示虚拟年份
月份:'%b\'%y',
年份:'%Y'
}
},
yAxis:[{//主yAxis
标签:{
风格:{
fontSize:'13px',
字体系列:“Arial,无衬线”
},
格式化程序:函数(){
返回“$”+Highcharts.numberFormat(此.value,2,“,”,”);
}
},
标题:{
文本:“”,
风格:{
颜色:“#89A54E”
},
},
最大值:.85,
相反:对
},{//次雅克西
网格线宽:0,
标题:{
文本:“”
},
最低:9000,
最高:12000,
标签:{
风格:{
fontSize:'13px',
字体系列:“Arial,无衬线”
},
格式化程序:函数(){
返回“$”+Highcharts.numberFormat(此.value,0,“.”,“,”);
}
}
}],
工具提示:{
已启用:false
},
打印选项:{
行:{
数据标签:{
启用:对,
是的,
格式化程序:函数(){
if(this.y==10000){
返回“$”+Highcharts.numberFormat(Math.round(this.y)),0,“.”,“,”+”;
}否则,如果(此.y>5){
返回“$”+Highcharts.numberFormat(Math.round(this.y)),0,“.”,“,”+”;
}else if(this.x==Date.UTC(2011,11,1)){//获取特殊日期的值并分配调整类,以便调整标签间距
返回“$”+Highcharts.numberFormat(this.y,3,“.”,“,”+”;
}如果(this.x==Date.UTC(2012,1,1)){
返回“$”+Highcharts.numberFormat(this.y,3,“.”,“,”+”;
}如果(this.x==Date.UTC(2011,7,1)| | this.x==Date.UTC(2012,7,1)){
返回“$”+Highcharts.numberFormat(this.y,2,”,“,”+”;
}else if(this.x==Date.UTC(2012,0,17)){
返回“$”+Highcharts.numberFormat(this.y,3,“.”,“,”+”;
}
}}
}
},
学分:{
已启用:false
},
系列:[{
名称:“投资增长1万美元”,
键入:“行”,
颜色:“#002d56”,
亚克西斯:1,,
数据:[
[UTC日期(2011年5月1日),10000],
[UTC日期(2011年8月1日),9996],
[UTC日期(2011年11月1日),10652],
[UTC日期(2012年2月1日),11387],
[UTC日期(2012年5月1日),11586],
[UTC日期(2012年8月1日),11984],
[UTC日期(2012年11月1日),12179]
]
}, {
名称:'每股历史分配',
颜色:‘#762123’,
键入:“行”,
enableMouseTracking:false,
数据:[
[UTC日期(2011年5月1日),0.70],
[UTC日期(2011年6月1日),0.70],
[UTC日期(2011年7月1日),0.70],
[UTC日期(2011年8月1日),0.70],
[UTC日期(2011年9月1日),0.70],
[UTC日期(2011年9月25日),0.70],
[UTC日期(2011年10月1日),0.717],
[UTC日期(2011年11月1日),0.717],
[UTC日期(2012,0,10),0.717],
[UTC日期(2012年0月17日),0.728],
[UTC日期(2012,0,24),0.728],
[UTC日期(2012,0,31),0.745],
[UTC日期(2012年1月1日),0.745],
[UTC日期(2012年1月28日),0.745],
[UTC日期(2012年2月6日),0.76],
[UTC日期(2012年2月13日),0.76],
[UTC日期(2012年2月20日),0.76],
[UTC日期(2012年2月27日),0.76],
[UTC日期(2012年3月3日),0.76],
[UTC日期(2012年3月10日),0.76],
[UTC日期(2012年3月17日),0.76],
[UTC日期(2012年3月24日),0.76],
[UTC日期(2012年4月1日),0.76],
[UTC日期(2012年4月8日),0.76],
[UTC日期(2012年4月15日),0.76],
[UTC日期(2012年4月22日),0.76],
[UTC日期(2012年4月29日),0.76],
[UTC日期(2012年5月5日),0.76],
[日期:UTC(2012,
...
tickInterval: 30 * 24 * 3600 * 1000,
...