Highcharts实现下钻多柱series

钻取功能需要引入或注册额外的功能模块,链接是官方模块的引入文档。

前言

  • Highcharts实现下钻动态添加多个series

实现

<template>
  <div
    ref="chartRef"
    style="height:300px;width:800px"
  >
  </div>
</template>

<script>
import Highcharts from "highcharts";
import HighchartsDrilldown from "highcharts/modules/drilldown";
HighchartsDrilldown(Highcharts);

import { onMounted, ref } from "vue";

export default {
  components: {},
  props: {},
  setup() {
    const chartRef = ref(null);

    onMounted(() => {
      initChart();
    });

    function initChart() {
      let chart = Highcharts.chart(chartRef.value, {
        credits: {
          enabled: false,
        },
        chart: {
          type: "column",
          events: {
            drilldown: async function (e) {
            	// const drilldownId = e.point.drilldown 
            	// 可根据drilldownId 找到你要下钻的数据, 此处demo直接用模拟数据

              let area = {
                name: "10月面积",
                id: 10,
                color: "#F56C6C",
                data: [
                  {
                    name: "1",
                    y: 100,
                  },
                  {
                    name: "2",
                    y: 200,
                  },
                  {
                    name: "3",
                    y: 400,
                  },
                ],
              };
              chart.addSingleSeriesAsDrilldown(e.point, area);

              let passArea = {
                name: "10月合格面积",
                id: 10,
                color: "#42b983",
                data: [
                  {
                    name: "1",
                    y: 70,
                  },
                  {
                    name: "2",
                    y: 90,
                  },
                  {
                    name: "3",
                    y: 200,
                  },
                ],
              };
              chart.addSingleSeriesAsDrilldown(e.point, passArea);
              chart.applyDrilldown();
            },
          },
        },
        legend: {
          verticalAlign: "top",
        },
        title: {
          text: null,
        },
        subtitle: {
          text: "单击列,展示更多详细信息",
        },
        xAxis: {
          type: "category",
          crosshair: true,
        },
        yAxis: {
          title: {
            text: "面积",
          },
        },
        series: [
          {
            name: "面积",
            data: [
              {
                name: "10月",
                y: 1231,
                drilldown: 10,
              },
            ],
            color: "#F56C6C",
          },
          {
            name: "合格面积",
            data: [
              {
                name: "10月",
                y: 443,
                drilldown: 10,
              },
            ],
            color: "#42b983",
          },
        ],
        drilldown: {
          drillUpButton: {
            position: {
              y: -32,
            },
          },
        },
      });

      chart.options.lang.drillUpText = "◁ Back";
    }

    return {
      chartRef,
    };
  },
};
</script>

效果

  • 动画没录入
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值