SOURCE

console 命令行工具 X clear

                    
>
console
window.onload = () => {
    var data = [1120, 932, 901, 934, 1290, 1330, 1320];
    var maxVal = Math.max(...data)
    var minVal = Math.min(...data)
    var threshold = 1200
    var thresholdOffset = (maxVal - threshold) / (maxVal - minVal)
    var option = {
        xAxis: {
            type: 'category',
            data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            data: data.map(v => ({
                value: v,
                itemStyle: {
                    color: v > threshold ? 'red' : 'green'
                }
            })),
            type: 'line',
            itemStyle: {  
                normal: { //颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
                    lineStyle: {        // 系列级个性化折线样式  
                        width: 3,  
                        type: 'solid',  
                        // color: "#0180ff" //折线的颜色
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1,
                            [
                                { offset: 0, color: 'red' },
                                { offset: thresholdOffset, color: 'red' },
                                { offset: thresholdOffset, color: 'green' },
                                { offset: 1, color: 'green' }
                            ]
                        )
                    }  
                }
            }
        }]
    };
    var ele = document.querySelector('#chart')
    console.log(ele)
    echarts.init(document.querySelector('#chart')).setOption(option)
}
<div id="chart" style="width=100vw; height: 100vh">sd</div>
* {
    margin: 0
}

本项目引用的自定义外部资源