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>
相关推荐
IT_陈寒22 分钟前
React性能优化实战:这5个Hooks技巧让我的应用快了40%
前端·人工智能·后端
江天澄38 分钟前
HTML5 中常用的语义化标签及其简要说明
前端·html·html5
知识分享小能手42 分钟前
jQuery 入门学习教程,从入门到精通, jQuery在HTML5中的应用(16)
前端·javascript·学习·ui·jquery·html5·1024程序员节
2501_918126911 小时前
用html5写一个打巴掌大赛
css·css3·html5
美摄科技1 小时前
H5短视频SDK,赋能Web端视频创作革命
前端·音视频
常常不爱学习1 小时前
Vue3 + TypeScript学习
开发语言·css·学习·typescript·html
黄毛火烧雪下1 小时前
React Native (RN)项目在web、Android和IOS上运行
android·前端·react native
fruge1 小时前
前端正则表达式实战合集:表单验证与字符串处理高频场景
前端·正则表达式
baozj1 小时前
🚀 手动改 500 个文件?不存在的!我用 AST 撸了个 Vue 国际化神器
前端·javascript·vue.js
用户4099322502121 小时前
为什么Vue 3的计算属性能解决模板臃肿、性能优化和双向同步三大痛点?
前端·ai编程·trae