Echarts饼状图-柱状图点击事件

1、饼状图

 var chart = this.$charts.chart("chartBox", {
                chart: {
                    type: "pie",
                    backgroundColor: "transparent",
                    options3d: {
                        enabled: true,
                        alpha: 30,
                    },
                    spacing: [0, 0, 0, 0],
                },
                title: {
                    verticalAlign: "middle", //标题在环的中间显示
                    text: this.total,//总数
                    style: {
                        fontSize: "18px",
                        color: "#ffffff",
                    },
                },
                tooltip: {
                    pointFormat: "{series.name}:{point.percentage:.2f}%",
                    style: {
                        fontSize: "14px",
                        color: "#000000",
                    },
                },
                plotOptions: {
                   
                    pie: {
 point: {
                            events: {
                                click: function (event) {
                                    // 在这里添加点击事件的处理逻辑
                                    console.log("点击了饼图:", event.point.name, event.point.y);
                                   
                                },
                            },
                        },
                        allowPointSelect: true,
                        cursor: "pointer",
                        showInLegend: false,
                        innerSize: 60,
                        depth: 30,
                        dataLabels: {
                            enabled: false,
                            format: "<b>{point.name}</b>: {point.percentage:.1f} %",
                            style: {
                                color:
                                    (this.$charts.theme &&
                                        this.$charts.theme.contrastTextColor) ||
                                    "black",
                            },
                        },
                    },
                },
                credits: {
                    enabled: false,
                },
                exporting: {
                    enabled: false,
                },
                colors: ["#00FFFF", "#00B7EE", "#007BEE", "#00EEA2", "#8DE022"],
                series: [
                    {
                        name: "",
                        data: this.info,//数据
                    },
                ],
            })

2、柱状图

  const chartDom = document.getElementById("chartBox")
            var myChart = this.$echarts.init(chartDom)
            myChart.resize()
            var option
            option = {
                grid: {
                    top: "10",
                    bottom: "20",
                    left: "50",
                    right: "40",
                },
                xAxis: {
                    type: "value",
                    axisLine: { show: false },
                    axisTick: { show: false },
                    axisLabel: { show: false },
                    splitLine: { show: false },
                },
                label: {
                    position: "right",
                    show: true,
                },
                yAxis: {
                    type: "category",
                    data: ["标题1", "标题", "标题", "标题", "标题"],
                    axisLine: { show: false },
                    axisTick: { show: false },
                    axisLabel: {
                        color: "#ffffff",
                    },
                },
                series: [
                    {
                        data: this.data,//数据
                        type: "bar",
                        showBackground: true,
                        backgroundStyle: {
                            color: "#e4e7ed",
                        },
                        backgroundStyle: {
                            color: "rgba(180, 180, 180, 0.2)",
                        },
                        itemStyle: {
                            normal: {
                                barWidth: 20, // 每个柱子的宽度
                            },
                        },
                    },
                ],
            }
            myChart.on('click', function(params) {
                console.log('点击了柱状图:', params.name,params.data);
            });
            option && myChart.setOption(option)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Angus-zoe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值