场景:在绘制折线图时,通常需要使用基线做为参考值进行比较,如何绘制水平基线,表示平均值,最大值,最小值,或者固定值?

措施:echarts中为标线markLine,type有average,min,max取值

option = {
    title: {
        text: '某楼盘销售情况',
        subtext: '纯属虚构'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data:['意向','预购','成交']
    },
    toolbox: {
        show: true,
        feature: {
            magicType: {show: true, type: ['stack', 'tiled']},
            saveAsImage: {show: true}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['周一','周二','周三','周四','周五','周六','周日']
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        name: '成交',
        type: 'line',
        smooth: true,
        markLine: {
             data: [{
                 name: '平均线',
                 // 支持 'average', 'min', 'max'
                 type: 'max'
        }]},
        data: [10, 12, 21, 54, 260, 830, 710]
    },
    {
        name: '预购',
        type: 'line',
        symbol:'diamond',
        markLine: {
                    label: {
                        position: 'middle'
                    },
                    data: [
                        { yAxis: 1200}
                    ]
                   }
    },
    {
        name: '意向',
        type: 'line',
        smooth: true,
        markLine: {
            data:[
                [ {
                  // 起点和终点的项会共用一个 name
                  name: '最小值到最大值',
                  type: 'min'
                },
                {
                 type: 'max'
                }]
             ]
        },
        data: [1320, 1132, 601, 234, 120, 90, 20]
    }]
};

效果如下:

01-26 23:34