echart js给相关参数赋值的问题

发布时间 2023-04-03 20:20:56作者: lingmin210

需要在初始化的时候加上相关的定义,后面用js进行动态赋值的时候才能找到,否则报Undefined,

定义:

var option = {
    title: { text: '', textStyle: { color: '#5AC8FA' } },
    //color: '#00ff00',
    legend: {
        show:true,
        data: [],
        x:'right',
        y:'top',
        textStyle: {
            color: '#00ff00'
        },
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            lable: {
            }
        }
    },
    grid: {
        left: 50,
        right: 0,
        top: 40,
        bottom: 20
    },

    xAxis: { data: [], name: '',
        axisTick:{
            show:true // 显示坐标轴刻度线
        },
        axisLine: {
            show: true, // 不显示坐标轴线
        },
        axisLabel: {
            show: true, // 不显示坐标轴上的文字
            textStyle: {
                color: '#6afffd'//修改坐标轴字体颜色
            },
        },
        splitLine:{
            show:true,// 不显示网格线
            formatter: '{value}',
            lineStyle:{
                type:'dashed',
                color: ['#373c73'],
            }
        }

    },
    yAxis: {
        type: 'value',
        name: '',
        min: 0,
        // max: 50,
        show:true, // 显示坐标轴线、坐标轴刻度线和坐标轴上的文字
        axisTick:{
            show:true // 显示坐标轴刻度线
        },
        axisLine: {
            show: false, // 不显示坐标轴线
        },
        axisLabel: {
            show: true, // 显示坐标轴上的文字
        },
        splitLine:{
            show:true ,// 显示网格线
            lineStyle:{
                color: ['#373c73'],
                type:'dashed'//虚线
            }
        },
        axisLabel: {
            formatter: '{value}',
            textStyle: {
                color: '#6afffd'//修改坐标轴字体颜色
            },
        },
        textStyle: {
            show: true,
            fontFamily: '微软雅黑',
            color: "#FFFF00",
            fontSize: '10',
        },

    },
    axisLabel:{
        interval:5,
        rotate:0,//倾斜度 -90 至 90 默认为0
        margin:2,
        textStyle:{
            fontWeight:"bolder",
            color:"#000000"
        }
    },
    series: []
};

var serie={
    name: '',
    type: 'line',
    symbol: 'circle',
    symbolSize: '3',
    data: [],
    markLine: {
        itemStyle: {
            normal: { lineStyle: { type: 'dashed', color: '#ffff00' }, label: { show: true, position: 'end' } },
        },

        data: [{yAxis: '40',lineStyle: {color: '#ffff00'}},
            {yAxis: '25',lineStyle: {color: '#ffff00'}}
        ]
    }
}

最后有底色的两行是markLine线的颜色标记,之后js中赋值如下:

 if (typeof(item.thresholdHihi) != undefined) {
                            dicOption.find(room.groupName).series[itemIndex].markLine.data[1].yAxis=item.thresholdHihi;
                            dicOption.find(room.groupName).series[itemIndex].markLine.data[1].lineStyle.color='#ff0000';
                        }