吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1330|回复: 10
收起左侧

[其他原创] 闲的无聊模仿某为的运动健康写的echarts

  [复制链接]
被遗忘的路人 发表于 2023-4-21 15:57
在网上找了好久都没找到类似能参考的代码,索性就写完发出来让大家参考一下。
今天写的比较着急,有问题也在所难免,请大家口下留情,谢谢!

[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html, body {
            width: 100%;
            height: 100%;
        }

        #dom {
            width: 100%;
            height: 400px;
        }
    </style>
</head>
<body>
<div id="dom"></div>
</body>
<script src="./js/echarts.min.js"></script>
<script>
    (function () {
        let data = "11111111111111111111111111111111111111133333311111111111111222111111111111111111111333111333311111111111111111133111111111111111111114444444441111222333333333333333333333333333333311122211111111111111111111111111111111133111333333311111133311133333333111333311111113333311113333111111111111111122233222222221111111111111111113333331111111111111111111111111111111111111111111111111111111111111111111111111";

        let arr = [];
        let xAxisData = [];
        let value = 0;
        let echartsParams = [{
            xIndex: 1,
            name: '浅睡',
            y: 250,
            type: "1",
            color: {
                start: '#D540C2',
                end: '#C430DE'
            }
        }, {
            xIndex: 2,
            name: '快速眼动',
            y: 150,
            type: "2",
            color: {
                start: '#FC8977',
                end: '#F1758D'
            }
        }, {
            xIndex: 0,
            name: '深睡',
            y: 350,
            type: "3",
            color: {
                start: '#942DEC',
                end: '#8937E3'
            }
        }, {
            xIndex: 3,
            name: '清醒',
            y: 50,
            type: "4",
            color: {
                start: '#F1C139',
                end: '#F9B836'
            }
        }];
        for (let i = 0; i < data.length; i++) {
            xAxisData.push(i.toString());
            value = value + 1;
            if (data[i] !== data[i + 1]) {
                let before = {
                    type: i - value <= 0 ? null : data[i - value],
                    xIndex: i - value > 0 ? echartsParams[Number(data[i - value]) - 1].xIndex : null
                };
                let after = {
                    type: i < data.length - 2 ? data[i + 1] : null,
                    xIndex: i < data.length - 2 ? echartsParams[Number(data[i + 1]) - 1].xIndex : null
                };

                let markLineColor = {
                    start: "rgba(0,0,0,0)",
                    end: "rgba(0,0,0,0)"
                };
                if(i < data.length - 2) {
                    let currentIndex = echartsParams[Number(data[i]) - 1].xIndex;
                    let nextIndex = echartsParams[Number(data[i + 1]) - 1].xIndex;
                    markLineColor.start = currentIndex > nextIndex ? echartsParams[Number(data[i]) - 1].color.end : echartsParams[Number(data[i + 1]) - 1].color.end;
                    markLineColor.end = currentIndex > nextIndex ? echartsParams[Number(data[i + 1]) - 1].color.start : echartsParams[Number(data[i]) - 1].color.start
                }

                arr.push({
                    name: echartsParams[Number(data[i]) - 1].name,
                    type: data[i],
                    value: value,
                    valueTotal: i + 1,
                    xIndex: echartsParams[Number(data[i]) - 1].xIndex,
                    markLineY: {
                        start: i === data.length - 1 ? 0 : echartsParams[Number(data[i]) - 1].y,
                        end: i < data.length - 2 ? echartsParams[Number(data[i + 1]) - 1].y : 0
                    },
                    color: echartsParams[Number(data[i]) - 1].color,
                    before: before,
                    after: after,
                    markLineColor: markLineColor,
                    barBorderRadius: [
                        before.xIndex > echartsParams[Number(data[i]) - 1].xIndex ? 0 : 5,
                        after.xIndex > echartsParams[Number(data[i]) - 1].xIndex ? 0 : 5,
                        i === data.length - 1 ? 5 : after.xIndex > echartsParams[Number(data[i]) - 1].xIndex ? 5 : 0,
                        i - value + 1 === 0 ? 5 : before.xIndex > echartsParams[Number(data[i]) - 1].xIndex ? 5 : 0
                    ]
                })
                value = 0;
            }
        }

        let seriesData = [];
        arr.map(item => {
            seriesData.push({
                type: 'bar',
                stack: 'total',
                barCategoryGap: 40,
                label: {
                    show: false
                },
                data: [{
                    name: item.name,
                    value: item.value,
                    itemStyle: {
                        normal: {
                            barBorderRadius: item.barBorderRadius,
                            color: item.type === "3" ? new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: item.color.start
                            }, {
                                offset: 1,
                                color: item.color.end
                            }]) : "transparent"
                        }
                    }
                }, {
                    name: item.name,
                    value: item.value,
                    itemStyle: {
                        normal: {
                            barBorderRadius: item.barBorderRadius,
                            color: item.type === "1" ? new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: item.color.start
                            }, {
                                offset: 1,
                                color: item.color.end
                            }]) : "transparent"
                        }
                    }
                }, {
                    name: item.name,
                    value: item.value,
                    itemStyle: {
                        normal: {
                            barBorderRadius: item.barBorderRadius,
                            color: item.type === "2" ? new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: item.color.start
                            }, {
                                offset: 1,
                                color: item.color.end
                            }]) : "transparent"
                        }
                    }
                }, {
                    name: item.name,
                    value: item.value,
                    itemStyle: {
                        normal: {
                            barBorderRadius: item.barBorderRadius,
                            color: item.type === "4" ? new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: item.color.start
                            }, {
                                offset: 1,
                                color: item.color.end
                            }]) : "transparent"
                        }
                    }
                }],
                markLine: {
                    silent: true,
                    symbol: ['none', 'none'],
                    label: {
                        show: false
                    },
                    data: [[{
                        xAxis: item.valueTotal,
                        y: item.markLineY.start,
                        lineStyle: {
                            type: "solid",
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: item.markLineColor.start
                            }, {
                                offset: 1,
                                color: item.markLineColor.end
                            }]),
                            width: 1
                        }
                    }, {
                        xAxis: item.valueTotal,
                        y: item.markLineY.end,
                        lineStyle: {
                            type: "solid"
                        }
                    }]]
                }
            });
        })

        let myChart = echarts.init(document.getElementById("dom"));
        let option = {
            legend: {
                show: false
            },
            grid: {
                top: 0,
                left: 0,
                right: 0,
                bottom: 0,
                containLabel: true
            },
            xAxis: {
                type: 'value',
                data: xAxisData,
                min: 1,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                splitLine: {
                    show: false
                }
            },
            yAxis: {
                type: 'category',
                data: ['深睡', '浅睡', '快速眼动', '清醒'],
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                },
                splitLine: {
                    show: false
                }
            },
            series: seriesData
        };
        myChart.setOption(option);
    })();
</script>
</html>

免费评分

参与人数 3吾爱币 +9 热心值 +2 收起 理由
xiaoqianga7152 + 1 可以可以
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
wardenzzzz + 1 + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 被遗忘的路人 发表于 2023-4-21 15:59
没有多余的时间详细调

我写的

我写的

人家的

人家的
Zien0103 发表于 2023-4-21 16:10
apull 发表于 2023-4-21 16:30
keruim 发表于 2023-4-21 16:33
看着不错
andytang866 发表于 2023-4-21 16:46
厉害了 ,要怎么用 呢
bandishui 发表于 2023-4-21 21:25
佩服, 佩服
greatzdl 发表于 2023-4-26 17:23
模仿的不错,基本没啥区别,可能要加强的地方稍微不同
yauto 发表于 2023-4-28 08:42
某为下面的滑动按钮能不能实现一下
Stoic 发表于 2023-4-28 18:30
厉害厉害。。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-2 11:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表