html + css 手写漏斗图

html 复制代码
<div class="chart-block" style="width: 265px; margin: 0px auto;">
        <div class="grid-content">
            <div class="funnelChart" style="position: relative; font-size: 16px; color: rgb(255, 255, 255);
            font-weight: bold; height: 0px; text-align: center; width: 400px; margin-left: 0px;
            border-top: 40px solid rgb(60, 110, 240); border-left: 20px solid transparent; border-right: 20px solid transparent;">
                <span
                    style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">商业机会:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 360px; margin-left: 20px; border-top: 40px solid rgb(44, 166, 225); border-left: 20px solid transparent; border-right: 20px solid transparent;">
                <span
                    style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">邀约量房:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 320px; margin-left: 40px; border-top: 40px solid rgb(38, 168, 114); border-left: 22px solid transparent; border-right: 22px solid transparent;">
                <span
                    style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">设计:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 276px; margin-left: 62px; border-top: 40px solid rgb(255, 186, 18); border-left: 20px solid transparent; border-right: 20px solid transparent;">
            <span
                style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">报价:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 235px; margin-left: 83px; border-top: 40px solid rgb(255, 110, 76); border-left: 20px solid transparent; border-right: 20px solid transparent;">
            <span
                style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">邀客户到店:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 195px; margin-left: 103px; border-top: 40px solid rgb(225, 37, 27); border-left: 18px solid transparent; border-right: 18px solid transparent;">
            <span
                style="top: -28px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">签约或交定金:20个</span>
            </div>
        </div>
        <div class="grid-content">
            <div class="funnelChart"
                 style="position: relative; font-size: 16px; color: rgb(255, 255, 255); font-weight: bold; height: 0px; text-align: center; width: 86px; margin-left: 121px; border-top: 153px solid rgb(154, 145, 235); border-left: 80px solid transparent; border-right: 80px solid transparent;">
            <span
                style="top: -136px; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;">挂单:20个</span>
            </div>
        </div>
    </div>

实现原理通过:borderTop定宽 + borderLeft/borderRight控制其形状(梯形或者三角形) ,然后用marginLeft调整他的位置从而组装成漏斗图。

可调节vue代码demo:

bash 复制代码
<template>
    <div class="chart-block" style="width: 265px;margin: 0 auto;">
        修改的梯形索引: <a-input v-model:value="index"  placeholder="修改的梯形索引"/>
        宽度: <a-input-number v-model:value="customerOverview[index].funnleWidth" placeholder="左右角度" /><br />
        左右角度: <a-input-number v-model:value="customerOverview[index].nextWidth" placeholder="左右角度" /><br />
        左右间距: <a-input-number v-model:value="customerOverview[index].left" placeholder="左右间距" /><br />
        梯形高度: <a-input-number v-model:value="customerOverview[index].top" placeholder="梯形高度" /><br />
        <a-button type="primary" @click="download()">打印</a-button>
        <div class="grid-content"  v-for="(item , cuIndex) in customerOverview" :key="cuIndex">
            <div class="funnelChart" style="position: relative;font-size: 16px;color: #fff;font-weight: bold;height: 0; text-align: center;"
                 :style="{width:item.funnleWidth+'px', marginLeft: item.left +'px',
  borderTop: item.top + 'px solid '+funnleColor[cuIndex],
  borderLeft:item.nextWidth+'px solid transparent',
  borderRight: item.nextWidth+'px solid transparent'}">
                <span :style="{top: cuIndex === 6 ? '-136px' : '-28px'}" style="position: absolute;left: 50%;transform: translateX(-50%);white-space: nowrap;">{{ item.text }}</span>
            </div>
        </div>
    </div>
</template>
<script lang="ts">
import {Vue, Component} from 'vue-facing-decorator';

@Component({})
export default class chart extends Vue {
    //  修改的索引
    index = 0;
    funnleColor = ['#3C6EF0', '#2CA6E1', '#26A872', '#FFBA12', '#FF6E4C', '#E1251B', '#9a91eb'];
    customerOverview =[
        {funnleWidth: 400, nextWidth: 20, left: 0, top: 40, text: '商业机会:20个'},
        {funnleWidth: 360, nextWidth: 20, left: 20, top: 40, text: '邀约量房:20个'},
        {funnleWidth: 320, nextWidth: 22, left: 40, top: 40, text: '设计:20个'},
        {funnleWidth: 276, nextWidth: 20, left: 62, top: 40, text: '报价:20个'},
        {funnleWidth: 235, nextWidth: 20, left: 83, top: 40, text: '邀客户到店:20个'},
        {funnleWidth: 195, nextWidth: 18, left: 103, top: 40, text: '签约或交定金:20个'},
        {funnleWidth: 86, nextWidth: 80, left: 121, top: 153, text: '挂单:20个'},
    ];
    download() {
        console.log('customerOverview', this.customerOverview)
    }
}
</script>

<style scoped lang="less">

</style>
相关推荐
winfredzhang4 小时前
为长阅读而生:我做了一个「安静」的 PDF 阅读器
pdf·html
梦帮科技5 小时前
GRAVIS v4.0:基于Web的极速套利架构设计与实时数据流实现
前端·人工智能·rust·自动化·区块链·智能合约·数字货币
爱勇宝5 小时前
办公资料反复修改、补传、交接混乱,我做了个桌面工具来解决这件事
前端·后端·程序员
微信开发api-视频号协议6 小时前
企业微信外部群开发自动化实践过程
java·前端·微信·自动化·企业微信·ipad
甲维斯6 小时前
Fable5:20美金的顶级设计师!
前端·人工智能
kyriewen6 小时前
我同时用了 Claude Code、Cursor 和 Codex,说说三个工具的真实差距——2026 年选错工具比不用 AI 更浪费时间
前端·ai编程·claude
Jackson__6 小时前
为了拯救我的腰椎和颈椎,我做了款浏览器插件!
前端·javascript·开源
闲猫7 小时前
Python FastAPI + SQLAlchemy 入门教程:从零搭建你的第一个 Web 应用
前端·python·fastapi
林小帅7 小时前
NestJS v11 + Prisma v7 ESM 迁移配置解析
前端·javascript·后端
IT_陈寒7 小时前
React的setState竟然不是立刻生效的,害我调试半天
前端·人工智能·后端