score:2

you're passing down chartoptions into the highcharts component. if you've defined this data on the parent component, vue will have made it reactive, so when you change the data the chart will update automatically.

below is a basic example of how this would work:

<template>
  <div>
    <highcharts :options="chartoptions[0]"></highcharts>
    <highcharts :options="chartoptions[1]"></highcharts>
    <button @click="changedata">change data for first chart</button>
  </div>
</template>

<script>
import { chart } from "highcharts-vue";

export default {
  components: {
    highcharts: chart
  },
  data() {
    return {
      chartoptions: [
        {
          series: [
            {
              data: [1, 2, 3]
            }
          ]
        },
        {
          series: [
            {
              data: [4, 5, 6]
            }
          ]
        },
      ]
    }
  },
  methods: {
    changedata() {
      this.chartoptions[0].series[0].data = [4, 8, 1];
    }
  }
};
</script>

edit:

to create multiple charts with the same options, you could create a custom chart component, and pass in just the data series as a prop:

<template>
  <highcharts :options="chartoptions"></highcharts>
</template>

<script>
import { chart } from "highcharts-vue";

export default {
  name: 'custompie',
  components: {
    highcharts: chart
  },
  props: ['data'],
  data() {
    return {
      chartoptions: {
        chart: {
          type: "pie"
        },
        title: {
          text: ""
        },
        credits: {
          enabled: false
        },
        plotoptions: {
          pie: {
            allowpointselect: true,
            cursor: "pointer",
            datalabels: {
              enabled: true,
              format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            }
          }
        },
        series: [
          { 
            name: 'comparison',
            data: this.data,
          },
        ]
      },
    }
  },
  watch: {
    data(newval) {
      this.chartoptions.series[0].data = newval;
    }
  }
};
</script>

note that you have to set up a watcher on the data prop, in order to update the components chartoptions when the data changes.

and your parent component (where you're displaying the charts) would look something like this:

<template>
  <div>
    <custompie :data="chartdata1" />
    <custompie :data="chartdata2" />
    <button @click="changedata">change data for first chart</button>
  </div>
</template>

<script>
import custompie from "./custompie";

export default {
  components: {
    custompie
  },
  data() {
    return {
      chartdata1: [1,2,3],
      chartdata2: [4,5,6]
    }
  },
  methods: {
    changedata() {
      this.chartdata1 = [4, 8, 1];
    }
  }
};
</script>

Related Query

More Query from same tag