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>
相关推荐
speedoooo10 小时前
在现有App里嵌入一个AI协作者
前端·ui·小程序·前端框架·web app
全栈胖叔叔-瓜州10 小时前
关于llamasharp 大模型多轮对话,模型对话无法终止,或者输出角色标识User:,或者System等角色标识问题。
前端·人工智能
三七吃山漆11 小时前
攻防世界——wife_wife
前端·javascript·web安全·网络安全·ctf
用户479492835691511 小时前
面试官问"try-catch影响性能吗",我用数据打脸
前端·javascript·面试
GISer_Jing11 小时前
前端营销技术实战:数据+AI实战指南
前端·javascript·人工智能
GIS之路11 小时前
使用命令行工具 ogr2ogr 将 CSV 转换为 Shp 数据(二)
前端
嘉琪00111 小时前
Vue3+JS 高级前端面试题
开发语言·前端·javascript
vipbic12 小时前
用 Turborepo 打造 Strapi 插件开发的极速全栈体验
前端·javascript
天涯学馆12 小时前
为什么 JavaScript 可以单线程却能处理异步?
前端·javascript
Henry_Lau61713 小时前
主流IDE常用快捷键对照
前端·css·ide