大数据canvas

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .top-state-total {
            display: flex;
            justify-content: space-between;
            color: #000;
            text-align: center;
        }

        .top-state-total .single {
            position: relative;
        }

        .top-state-total .single span {
            position: absolute;
            left: 60px;
            top: 45px;
            font-size: 14px;
        }

        .top-state-total .single span b {
            font-size: 25px;
        }
    </style>
</head>

<body>
    <div class='top-state-total' id="stateTotal"></div>
    <script>
        function drawLabel(canvas, textInfo) {
            var ctx = canvas.getContext('2d'),
                text = textInfo.text,
                idx = textInfo.lineWid,
                colorValue = "#049188";
            canvas.width = idx;
            ctx.fillStyle = colorValue;
            //畫圓
            ctx.beginPath();
            ctx.arc(35, 55, 2, 0, 2 * Math.PI, false);
            ctx.fill();
            //折線
            ctx.moveTo(35, 55);
            ctx.lineTo(60, 80);
            ctx.lineTo(idx, 80);
            ctx.lineWidth = 1;
            ctx.strokeStyle = colorValue;
            ctx.stroke();
            //文字
            ctx.font = '12px Georgia';
            ctx.fillText(text, 60, 92);
        }
        var stateList = document.getElementById('stateTotal'),
            titleObj = [
                {
                    text: '接入終端數量1',
                    lineWid: 160,
                    num: 100,
                    unit: '臺'
                }, {
                    text: '接入終端數量2',
                    lineWid: 160,
                    num: 200,
                    unit: '臺'
                }, {
                    text: '接入終端數量3',
                    lineWid: 160,
                    num: 300,
                    unit: '臺'
                }, {
                    text: '接入終端數量4',
                    lineWid: 160,
                    num: 400,
                    unit: '臺'
                }, {
                    text: '接入終端數量4',
                    lineWid: 160,
                    num: 500,
                    unit: '臺'
                }, {
                    text: '接入終端數量4',
                    lineWid: 160,
                    num: 600,
                    unit: '臺'
                }
            ];

        titleObj.forEach(function (o, i) {
            stateList.innerHTML += `<div class="single">
            <canvas height="100" width='${o.lineWid}'></canvas>
            <span><b>${o.num}</b>${o.unit}</span>
        </div> `
        });
        stateList.querySelectorAll('canvas').forEach(function (item, idx) {
            drawLabel(item, titleObj[idx]);
        })
    </script>
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值