猿问

更改 echarts 库中的 xaxis 标签

var data = [];

var dataCount = 10;

var startTime = +new Date();

var categories = ['categoryA', 'categoryB', 'categoryC'];

var types = [

    {name: 'JS Heap', color: '#7b9ce1'},

    {name: 'Documents', color: '#bd6d6c'},

    {name: 'Nodes', color: '#75d874'},

    {name: 'Listeners', color: '#e0bc78'},

    {name: 'GPU Memory', color: '#dc77dc'},

    {name: 'GPU', color: '#72b362'}

];


// Generate mock data

echarts.util.each(categories, function (category, index) {

    var baseTime = startTime;

    for (var i = 0; i < dataCount; i++) {

        var typeItem = types[Math.round(Math.random() * (types.length - 1))];

        var duration = Math.round(Math.random() * 10000);

        data.push({

            name: typeItem.name,

            value: [

                index,

                baseTime,

                baseTime += duration,

                duration

            ],

            itemStyle: {

                normal: {

                    color: typeItem.color

                }

            }

        });

        baseTime += Math.round(Math.random() * 2000);

    }

});


function renderItem(params, api) {

    var categoryIndex = api.value(0);

    var start = api.coord([api.value(1), categoryIndex]);

    var end = api.coord([api.value(2), categoryIndex]);

    var height = api.size([0, 1])[1] * 0.6;


    var rectShape = echarts.graphic.clipRectByRect({

        x: start[0],

        y: start[1] - height / 2,

        width: end[0] - start[0],

        height: height

    }, {

        x: params.coordSys.x,

        y: params.coordSys.y,

        width: params.coordSys.width,

        height: params.coordSys.height

    });


    return rectShape && {

        type: 'rect',

        shape: rectShape,

        style: api.style()

    };

}


大家好!!我正在处理 echarts 库,我唯一想更改数据的是 Xaxis 部分的axisLabel。


我的意思是,例如,“2019-11-5、2019-11-6....”等等。所以,希望有人能帮帮我,非常感谢!!!


大家好!!我正在处理 echarts 库,我唯一想更改数据的是 Xaxis 部分的axisLabel。


我的意思是,例如,“2019-11-5、2019-11-6....”等等。所以,希望有人能帮帮我,非常感谢!!!


德玛西亚99
浏览 349回答 1
1回答

慕的地10843

首先,创建一个日期数组,如var dates = ['2019-11-5','2019-10-3','2019-2-2','2019-1-4','2019-12-5'];然后在 xAxis -> axisLabel 返回日期axisLabel: {&nbsp; &nbsp; &nbsp; &nbsp; formatter: function (val,index) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return dates[index];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答