javascript 如何增加 highchart.js 图表上 x 轴标签区域的高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11421748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:09:12  来源:igfitidea点击:

How do you increase the height of the x-axis labels area on a highchart.js chart?

javascriptcsshighcharts

提问by Justin

I have a simple line graph created by highcharts.js. I have a lot of tick marks in the x-axis (30), so I set stagger to 2 deal with the marks overlapping each other horizontally. However, the lower row of x-axis tick labels is being cut off by the end of the chart.

我有一个由 highcharts.js 创建的简单折线图。我在 x 轴 (30) 上有很多刻度线,所以我将 stagger 设置为 2 处理水平相互重叠的标记。但是,图表末尾的 x 轴刻度标签的下一行被截断。

No matter how tall I make the chart the lower row of x-axis tick mark labels is cut off. How can I increase the height of this area to fix this? Or is there some other method?

无论我制作图表多高,x 轴刻度标记标签的下一行都会被切断。我怎样才能增加这个区域的高度来解决这个问题?或者有其他方法吗?

month_chart = new Highcharts.Chart({
chart: {
    borderRadius: 0,
    height: chart_height,
    marginRight: 30,
    marginBottom: 25,
    renderTo: 'leads-by-month',
    type: 'line',
},
title: {
    text: 'Past 30 Days',
},
xAxis: {
    categories: [<?php print $bymonth_categories; ?>],
    labels: {
        staggerLines: 2,
    },
},
yAxis: {
    title: {
        text: 'Leads',
        style: {color: '#3d3e41', }
    },
    plotLines: [{
        value: 0,
        width: 1,
        color: '#808080'
    }],
    min: 0,
},
plotOptions: {
    line: {
        color: '#578df1',
        dataLabels: {
            enabled: true,
            color: '#3d3e41',
        },
        enableMouseTracking: false
    }
},
legend: {
    layout: 'vertical',
    align: 'right',
    verticalAlign: 'top',
    x: -100,
    y: 74,
    floating: true,
    borderWidth: 1,
    backgroundColor: '#FFFFFF',
    shadow: true
},
series: [{
    name: '<?php print $organization['name']; ?>',
    data: [<?php print $bymonth_data; ?>]
}]
        });

回答by Mark

Just bump up the marginBottomoption. The default is 70 which should be plenty for 2 rows of tick labels, you've set it to 25 which is not.

只需提高marginBottom选项。默认值为 70,这对于 2 行刻度标签应该足够了,您已将其设置为 25,但事实并非如此。