为了账号安全,请及时绑定邮箱和手机立即绑定

更改 echarts 库中的 xaxis 标签

更改 echarts 库中的 xaxis 标签

德玛西亚99 2021-12-23 14:45:02
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 dataecharts.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....”等等。所以,希望有人能帮帮我,非常感谢!!!
查看完整描述

1 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

首先,创建一个日期数组,如


var dates = ['2019-11-5','2019-10-3','2019-2-2','2019-1-4','2019-12-5'];

然后在 xAxis -> axisLabel 返回日期


axisLabel: {

        formatter: function (val,index) {

            return dates[index];

        }

    }


查看完整回答
反对 回复 2021-12-23
  • 1 回答
  • 0 关注
  • 348 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号