echart vue3 柱状图 自定义柱子颜色和文字颜色

目录

需求:

效果:

​编辑数据格式:series


需求:

自定义echart柱状图的柱子颜色

并且每根柱子上数字的颜色要跟柱状图的颜色保持一致

效果:

数据格式:series

[
    {
        "name": "预算",
        "data": [
            {
                "itemStyle": {
                    "color": "#CDD2DB"
                },
                "label": {
                    "textStyle": {
                        "color": "#CDD2DB"
                    }
                },
                "value": "40.4"
            },
            {
                "itemStyle": {
                    "color": "#CDD2DB"
                },
                "label": {
                    "textStyle": {
                        "color": "#CDD2DB"
                    }
                },
                "value": "88.5"
            },
            {
                "itemStyle": {
                    "color": "#CDD2DB"
                },
                "label": {
                    "textStyle": {
                        "color": "#CDD2DB"
                    }
                },
                "value": "29.1"
            },
            {
                "itemStyle": {
                    "color": "#CDD2DB"
                },
                "label": {
                    "textStyle": {
                        "color": "#CDD2DB"
                    }
                },
                "value": "66.6"
            }
        ],
        "type": "bar",
        "barWidth": "10",
        "barMaxWidth": "10",
        "barMinWidth": "0",
        "barGap": "0",
        "showBackground": false,
        "itemStyle": {
            "normal": {
                "barBorderRadius": [
                    2,
                    2,
                    2,
                    2
                ],
                "label": {
                    "confine": true,
                    "show": true,
                    "position": "top",
                    "textStyle": {
                        "color": "#C09F88",
                        "fontSize": 10
                    }
                }
            }
        },
        "backgroundStyle": {
            "color": "rgba(255, 255, 255, 0.1)"
        }
    },
    {
        "name": "实际",
        "data": [
            {
                "itemStyle": {
                    "color": "#31D029"
                },
                "label": {
                    "textStyle": {
                        "color": "#31D029"
                    }
                },
                "value": "51.8"
            },
            {
                "itemStyle": {
                    "color": "#ED1A2C"
                },
                "label": {
                    "textStyle": {
                        "color": "#ED1A2C"
                    }
                },
                "value": "87.7"
            },
            {
                "itemStyle": {
                    "color": "#31D029"
                },
                "label": {
                    "textStyle": {
                        "color": "#31D029"
                    }
                },
                "value": "36.8"
            },
            {
                "itemStyle": {
                    "color": "#31D029"
                },
                "label": {
                    "textStyle": {
                        "color": "#31D029"
                    }
                },
                "value": "70.3"
            }
        ],
        "type": "bar",
        "barWidth": "10",
        "barMaxWidth": "10",
        "barMinWidth": "0",
        "barGap": "200%",
        "showBackground": false,
        "itemStyle": {
            "normal": {
                "barBorderRadius": [
                    2,
                    2,
                    2,
                    2
                ],
                "label": {
                    "confine": true,
                    "show": true,
                    "position": "top",
                    "textStyle": {
                        "color": "#C09F88",
                        "fontSize": 10
                    }
                }
            }
        },
        "backgroundStyle": {
            "color": "rgba(255, 255, 255, 0.1)"
        }
    }
]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于使用 Vue 3 和 ECharts 创建柱状图,您可以按照以下步骤进行操作: 1. 首先,确保您已经安装了 Vue 3 和 ECharts。可以使用以下命令进行安装: ```bash npm install vue@next echarts ``` 2. 在 Vue 组件中引入 ECharts 和其样式文件。可以在 `main.js` 或者需要使用柱状图的组件中进行引入: ```javascript import { createApp } from 'vue'; import * as echarts from 'echarts'; import 'echarts/dist/echarts.min.css'; const app = createApp(App); app.config.globalProperties.$echarts = echarts; app.mount('#app'); ``` 3. 在需要显示柱状图的组件中,创建一个容器来容纳图表,并引入 ECharts 的实例: ```html <template> <div class="chart-container"> <div ref="chart" style="width: 100%; height: 400px;"></div> </div> </template> <script> export default { mounted() { this.renderChart(); }, methods: { renderChart() { const chartDom = this.$refs.chart; const myChart = this.$echarts.init(chartDom); // 在这里使用 ECharts 的 API 绘制柱状图 // 例如: myChart.setOption({ title: { text: '柱状图示例' }, xAxis: { type: 'category', data: ['A', 'B', 'C', 'D', 'E'] }, yAxis: { type: 'value' }, series: [{ data: [10, 20, 30, 40, 50], type: 'bar' }] }); } } }; </script> <style scoped> .chart-container { width: 100%; height: 400px; } </style> ``` 以上是一个简单的示例,您可以根据您的需求进行进一步的配置和样式调整。希望对您有所帮助!如果您有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值