Echarts面积折线图如何实现?

摘要:项目开发中有个面积折线图的界面

实现:直接上代码吧,哈哈,简单明了

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>echarts面积折线图</title>
    <style>
        .centerItem {
            width: 856px;
            height: 640px;
            /* background-color: lightskyblue; */
            border: 1px solid #ccc;
            margin: 110px auto 0 auto;
        }
    </style>
</head>

<body>
    <!-- 折线展示 -->
    <div id="mjBox" class="centerItem"></div>

    <!-- 引入相关文件 -->
    <script src="js/jquery-3.2.1.min.js"></script>
    <!-- 引入 ECharts 文件 -->
    <script src="js/echarts.js"></script>

    <script>
        // 基于准备好的dom,初始化echarts实例
        var mjBoxEchart = echarts.init(document.getElementById('mjBox'));
        // 指定相关的配置项和数据
        var mjBoxOption = {
            legend: {
                data: ['吃饭', '睡觉', '打豆豆'],
                icon: 'rect',
                top: 22,
                right: 24,
                itemGap: 15,
                itemWidth: 10,
                itemHeight: 10,
                textStyle: {
                    // padding: [0, 0, 0, 5],
                    color: 'rgba(0,0,0,0.87)'
                }
            },
            color: ['#289df5', '#fbc01b', '#ff5050'],
            grid: {
                left: 24,
                right: '6%',
                bottom: '30',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                axisLine: {
                    show: false
                },
                axisTick: {
                    length: 0
                },
                axisLabel: {
                    interval: 0,
                    textStyle: {
                        color: '#00c5d7'
                    }
                },
                name: '(月)',
                nameTextStyle: {
                    padding: [24, 0, 0, 0],
                    color: '#00c5d7'
                },
                nameGap: 0,
                data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
            },
            yAxis: {
                type: 'value',
                axisLine: {
                    show: false
                },
                axisTick: {
                    length: 0 // 刻度线的长度
                },
                splitLine: {
                    lineStyle: {
                        color: ["#051d5f"],
                        width: 1,
                        type: 'solid'
                    }
                },
                axisLabel: {
                    textStyle: {
                        color: '#a3a4b2'
                    }
                }
            },
            series: [{
                name: '吃饭',
                type: 'line',
                smooth: true,
                symbol: 'circle', // 拐点类型
                symbolSize: 0, // 拐点圆的大小
                itemStyle: {
                    normal: {
                        color: '#289df5', // 折线条的颜色
                        borderColor: '#289df5', // 拐点边框颜色
                        areaStyle: {
                            type: 'default',
                            opacity: 0.1
                        }
                    }
                },
                data: [310, 212, 221, 154, 260, 430, 310, 110, 120, 210, 124, 60]
            }, {
                name: '睡觉',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 0,
                itemStyle: {
                    normal: {
                        color: '#fbc01b',
                        borderColor: '#fbc01b',
                        areaStyle: {
                            type: 'default',
                            opacity: 0.1
                        }
                    }
                },
                data: [151, 282, 151, 120, 120, 80, 130, 182, 234, 191, 90, 30]
            }, {
                name: '打豆豆',
                type: 'line',
                smooth: true,
                symbol: 'circle',
                symbolSize: 0,
                itemStyle: {
                    normal: {
                        color: '#ff5050',
                        borderColor: '#ff5050',
                        areaStyle: {
                            type: 'default',
                            opacity: 0.1
                        }
                    }
                },
                data: [120, 132, 70, 34, 60, 59, 140, 210, 124, 112, 23, 20]
            }]
        };
        // 使用制定的配置项和数据显示图表
        mjBoxEchart.setOption(mjBoxOption);
        // echart图表自适应
        window.addEventListener("resize", function() {
            zxBoxEchart.resize();
        });
    </script>

</body>

</html>

效果如下:

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
要在echarts折线图实现渐变效果,可以使用areaStyle和lineStyle属性来设置。在series中,通过设置areaStyle的color属性为一个线性渐变对象,可以实现区域面积的渐变效果。同时,通过设置lineStyle的color属性为一个线性渐变对象,可以实现折线的渐变颜色效果。 以下是一个示例代码,展示了如何在echarts折线图实现渐变效果: ```javascript const option = { xAxis: { type: 'category', data: \['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'\] }, yAxis: { type: 'value' }, series: \[ { type: 'line', smooth: true, showSymbol: false, lineStyle: { normal: { width: 4, color: new echarts.graphic.LinearGradient(0, 0, 1, 0, \[ { offset: 0, color: 'rgb(0, 255, 255, 0)' }, { offset: 0.2, color: 'rgb(0, 255, 255, 0)' }, { offset: 0.4, color: 'rgb(0, 200, 200, 80)' }, { offset: 0.6, color: 'rgb(0, 200, 200, 80)' }, { offset: 0.8, color: 'rgb(0, 255, 255, 0)' }, { offset: 1, color: 'rgb(0, 255, 255, 0)' } \]) } }, areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: \[ { offset: 0, color: 'rgb(0, 50, 100)' }, { offset: 0.5, color: 'rgb(0, 50, 100, 50)' }, { offset: 1, color: 'rgb(0, 50, 100, 0)' } \] } }, data: \[150, 230, 224, 218, 135, 147, 260\] } \] }; // 使用以上option配置绘制折线图 ``` 在上述代码中,通过设置lineStyle的color属性为一个线性渐变对象,实现折线的渐变颜色效果。同时,通过设置areaStyle的color属性为一个线性渐变对象,实现了区域面积的渐变效果。 希望这个示例能够帮助到你实现echarts折线图的渐变效果。 #### 引用[.reference_title] - *1* [Echarts折线图折线呈现为渐变线条](https://blog.csdn.net/u010234868/article/details/131475802)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [Echarts-折线图-设置线条颜色以及线条以下区域显示渐变颜色](https://blog.csdn.net/WQearl/article/details/120216290)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值