【源码】html+JS实现:24小时折线进度图

<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">  
    <title>24小时折线进度图</title>  
    <style>  
        body {  
            margin: 0;  
            padding: 0;  
            font-family: Arial, sans-serif;  
        }  
  
        #chart-container {  
            position: fixed;  
            bottom: 0;  
            left: 0;  
            right: 0;  
            background-color: transparent; /* 设置容器背景透明 */  
            display: flex;  
            justify-content: center;  
            align-items: flex-end;  
            padding: 20px;  
            box-sizing: border-box;  
        }  
  
        canvas {  
            background-color: transparent; /* 设置canvas背景透明 */  
        }  
    </style>  
</head>  
<body>  
    <!-- 页面其他内容 -->  
  
    <!-- 折线进度图容器 -->  
    <div id="chart-container">  
        <canvas id="myChart"></canvas>  
    </div>  
  
    <!-- Chart.js库 -->  
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>  
  
    <!-- 折线进度图JavaScript代码 -->  
    <script>  
        window.onload = function() {  
            var ctx = document.getElementById('myChart').getContext('2d');  
            var myChart = new Chart(ctx, {  
                type: 'line',  
                data: {  
                    labels: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00',  
                             '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'],  
                    datasets: [{  
                        label: '进度',  
                        data: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 70, 60, 50, 40, 30, 20, 10, 0, 10, 20, 30, 40, 50], // 示例数据  
                        backgroundColor: 'rgba(75, 192, 192, 0.3)', // 半透明背景色  
                        borderColor: 'rgba(75, 192, 192, 1)', // 边框颜色  
                        borderWidth: 2  
                    }]  
                },  
                options: {  
                    responsive: true,  
                    maintainAspectRatio: false,  
                    scales: {  
                        y: {  
                            beginAtZero: true,  
                            ticks: {  
                                callback: function(value) {  
                                    return value + '%'; // 自定义y轴刻度标签  
                                }  
                            }  
                        },  
                        x: {  
                            gridLines: {  
                                display: false // 隐藏x轴网格线  
                            },  
                            ticks: {  
                                maxRotation: 0, // 防止标签旋转  
                                autoSkip: false // 不自动跳过标签  
                            }  
                        }  
                    },  
                    legend: {  
                        display: false // 隐藏图例  
                    },  
                    tooltips: {  
                        enabled: false // 禁用提示框  
                    }  
                }  
            });  
        };  
    </script>  
</body>  
</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值