首页 > 解决方案 > 如何为长日期字符串增加轴下方的空间?

问题描述

底部Xaxis字段的echarts切割

请查看图片并告诉我是否可以选择增加此图像的边距/边框以适应长日期/时间字符串。

标签: javascriptecharts

解决方案


你可以设置grid选项可以实现这个目标:

grid.containLabel = true

如果你喜欢,还可以设置:

grid.bottom = 0

例如:

    option = {
    xAxis: {
        type: 'category',
        axisLabel: {
            interval: 1,
            rotate: 45
        },
        data: ['2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04', '2018-06-07 14:27:04']
    },
    yAxis: {
        type: 'value'
    },
    grid: {
        bottom: 0,
        containLabel: true
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290, 1330, 1320,820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true
    }]
};

结果: 在此处输入图像描述


推荐阅读