Echarts横向柱状图,带标题

效果图:

 

 

 首先安装echarts,看官网安装文档即可

然后要用的文件引入一下

import * as echarts from 'echarts';

我用的vue3,setup放标签里的

 

 

 

 

 代码如下:

复制代码
<div class="card">
<IdcTopTitleView :isShowPicker="true" bigText="辅材采购金额占比" />
<div id="centerFoot" style='height: 100%;width: 100%' />
</div>

<script setup>
import * as echarts from 'echarts';
import { onMounted, ref } from "vue";
import IdcTopTitleView from "./components/IdcTopTitleView.vue";
onMounted(() => {
  const centerFoot = echarts.init(document.getElementById('centerFoot')); 
    centerFoot.setOption({
        grid: {
            left: "6%",
            width: "80%",
            top: "2%",
        },
        xAxis: {
            type: "value",
            show: false
        },
        yAxis: [
            {
                type: "category",
                inverse: true,
                show: false,
                axisTick: {
                    show: false
                },
            },
            //      左侧上方名称
            {
                type: 'category',
                offset: -10,
                position: "left",
                axisLine: {
                    show: false
                },
                inverse: false,
                axisTick: {
                    show: false
                },
                axisLabel: {
                    interval: 0,
                    align: "left",
                    verticalAlign: "bottom",
                    lineHeight: 44,
                    fontSize: 14
                },
                data: ['空调滤清器', '碳纤维轮毂', '轮胎锁', '轮胎密封胶', '动力轮毂']
            },
            //      右侧上方名称
            {
                type: 'category',
                position: "right",
                axisLine: {
                    show: false
                },
                inverse: false,
                axisTick: {
                    show: false
                },
                axisLabel: {
                    interval: 0,
                    color: '#737373',
                    align: "right",
                    verticalAlign: "bottom",
                    lineHeight: 44,
                    fontSize: 14
                },
                //------------------文字描述----------------------------
                data: ['500/1000', '400/1000', '300/1000', '200/1000', '100/1000']
            }
        ],
        series: [
            {
                zlevel: 1,
                type: "bar",
                barWidth: "15px",
                animationDuration: 1500,
                //------------------数据及其样式----------------------------
                data: [
                    {
                        value: 10,
                        itemStyle: {
                            color: "#007CFF",
                        }
                    },
                    {
                        value: 20,
                        itemStyle: {
                            color: "#007CFF"
                        }
                    },
                    {
                        value: 30,
                        itemStyle: {
                            color: "#007CFF"
                        }
                    },
                    {
                        value: 40,
                        itemStyle: {
                            color: "#007CFF"
                        }
                    },
                    {
                        value: 50,
                        itemStyle: {
                            color: "#007CFF"
                        }
                    },
                ],
                align: "center",
            },
            {
                type: "bar",
                barWidth: 15,
                barGap: "-100%",

                //------------------背景按最大值----------------------------
                data: [100, 100, 100, 100, 100],
                itemStyle: {
                    normal: {
                        color: "#DEEDFF",
                        width: "100%",
                    },
                }
            }
        ]
    })
})
复制代码

简洁一点:

复制代码
const centerFoot = echarts.init(document.getElementById('centerFoot'));
centerFoot.setOption({
    grid:{//设置位置},
    xAxis: {
            type: "value",
            show: false
     },
    yAxis: [
        {// y轴样式},
        {// 左侧标题},
        {// 右侧数据}
    ],
    series:[
        {// 主柱状图样式},
        {// 背景柱状图样式}
    ]
    
})        
复制代码

 

posted @   幻影之舞  阅读(1464)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-11-18 vue中的mock
点击右上角即可分享
微信分享提示