Apex 甜甜圈图 - 无法获取要更新的标签

Pav*_*hev 2 vue.js apexcharts

我试图让 Apex 图表(在 Vue.js 中)也更新它们的标签。我使用以下示例作为基础:

https://apexcharts.com/vue-chart-demos/pie-charts/update-donut/

我做了一个非常基本的图表来演示这个问题。它在开始时有数据项和 3 个标签。更新按钮连接到更新事件。当您单击它时,数据会发生变化,但标签不会。都试过 - 直接设置:

this.chartOptions.labels = [] ...
Run Code Online (Sandbox Code Playgroud)

并使用 vue 机制:

this.$set(this.chartOptions, "labels", ["d", "e", "f"]);
Run Code Online (Sandbox Code Playgroud)

不过,他们似乎都没有改变标签。

这是它的代码笔:https : //codesandbox.io/s/vue-basic-example-z72rk?fontsize=14&hidenavigation=1&theme=dark

<template>
  <div class="example">
    <label>{{updated}}</label>
    <apexcharts width="300" height="300" type="donut" :options="chartOptions" :series="series"></apexcharts>
    <button v-on:click="changeChart">Update</button>
  </div>
</template>

    <script>
    import VueApexCharts from "vue-apexcharts";

    export default {
      name: "Chart",
      components: {
        apexcharts: VueApexCharts
      },
      data: function() {
        return {
          updated: "Not updated",
          chartOptions: {
            chart: {
              id: "basic-donut"
            },
            labels: ["a", "b", "c"]
          },
          series: [30, 40, 45]
        };
      },
      methods: {
        changeChart() {
          this.series = [1, 2, 3];
          this.chartOptions.labels = ["d", "e", "f"];
          this.$set(this.chartOptions, "labels", ["d", "e", "f"]);
          this.$set(this, "updated", "Updated");
        }
      }
    };
    </script>
Run Code Online (Sandbox Code Playgroud)

我想我对 Apex 饼图/甜甜圈图的工作方式缺少一些了解,但我似乎也无法在文档中找到它。

jun*_*ipa 5

更新中 chartOptions应该导致更新。

这是我刚刚测试过的完整工作代码,它运行良好

<template>
  <div class="app">
    <button @click="updateLabels()">Update Labels</button>

    <apexcharts type="donut" width="280" :options="chartOptions" :series="series"/>
  </div>
</template>

<script>
import VueApexCharts from "vue-apexcharts";

export default {
  name: "Chart",
  components: {
    apexcharts: VueApexCharts
  },
  data: function() {
    return {
      series: [44, 55, 41, 17, 15],
      chartOptions: {
        labels: ["a", "b", "c", "d", "e"]
      }
    };
  },
  methods: {
    updateLabels: function() {
      this.series= [Math.random() * 10, Math.random() * 10]
      this.chartOptions = {
        labels: [Math.random() * 10, Math.random() * 10],
      };
    }
  }
};
</script>

Run Code Online (Sandbox Code Playgroud)

这是代码沙盒的链接