我想使用ECharts创建类似时间线的条形图

时间:2019-02-15 13:15:25

标签: javascript echarts

我想将xAxis的标签更改为以1小时为间隔的小时。如何格式化xAxis数据?我不能将时间类型用于xAxis,因为它通常用于连续数据。

option = {
tooltip : {
        trigger: 'axis',
        axisPointer : {
            type : 'shadow'
        },
        formatter: function (params) {
            var tar;
            if (params[1].value != '-') {
                tar = params[1];
            }
            else {
                tar = params[0];
            }
            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value + ' min';
        }
    },
    legend: {
        data: ['Duration (minutes)']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis:  {
        type: 'value',
        formatter: '{value} kg'
    },
    yAxis: {
        type: 'category',
        data: ['2019-02-01','2019-02-02','2019-02-03','2019-02-04','2019-02-05','2019-02-06','2019-02-07']
    },
    series: [

        {
            type: 'bar',
            stack: '总量',
            itemStyle: {
                normal: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                },
                emphasis: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                }
            },
            data: [150, 212, 201, 154, 190, 330, 410]
        },
        {
            name: 'Duration (minutes)',
            type: 'bar',
            stack: '总量',
            itemStyle: {
                color: '#88c149'
            },
            label: {
                normal: {
                    show: true,
                    position: 'insideRight'
                }
            },
            data: [820, 832, 901, 934, 1290, 1330, 1320]
        }
    ]
};

I want to change the label of the xAxis into hours with 1 hour interval. How do I format the xAxis data?

0 个答案:

没有答案