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>
Source: stackoverflow.com
Related Query
- How to have multiple highcharts with different series data in vuejs without repeating code
- Highcharts : using same div to load a chart multiple times with different series data
- How to make multiple Y-axis with incoming series of data from database using Highcharts
- How to get multiple data series into Highcharts
- Highcharts with JSON data and multiple series
- Highcharts not displaying series data for graph with multiple Y-axes
- Highcharts show the same yAxis start and end value with multiple data series
- Highcharts - How to make a scatter plot with multiple series from HTML table
- Highcharts - how to create multiple y axis and group the data series
- How can I have both a legend and data labels, with different labels, in Highcharts?
- How to create pie chart with only 1 series data and have background be a circle
- Overlay 2 series of data of different length with highcharts
- How to update Highcharts with multiple series via JSON?
- Highcharts same types of data with different series
- Highcharts series visibility with csv data source
- Loading json data to highcharts with multiple series
- How can I change data series dynamically in HighCharts without overwriting initial series?
- Highcharts multiple series with missing Data Points
- HighCharts BoxPlot With Multiple Series Having Single Data
- How to dynamically addEvent to Highcharts series with multiple charts?
- How to update just data attribute under series in highcharts with json?
- How to render a bar chart with different series with only one entry per category in HighCharts
- Highcharts: How do I get columns to have specific color with multiple series
- In Highcharts How to keep rectangle such SVG elements attached with series data but not with pixel when resize,reflow,redraw,zooming in out?
- How to align multiple charts with different data
- How to get multiple series data in tooltip highcharts (Without loosing tooltip pointer arrow)
- Highcharts multiple series from JSON with different style depending on serie name
- How to set columnrange width to expand the length of the x-axis in multiple data series in Highcharts
- Highcharts - how to have a chart with dynamic height?
- How to get multiple series data in tooltip highcharts?
More Query from same tag
- Unknown Property – yii\base\UnknownPropertyException Setting unknown property: dosamigos\highcharts\HighCharts::scripts
- highchart chart redraw method is not refreshing the chart
- In a Highcharts heatmap is it possible for a data point to be ignored for the color scale?
- Highcharts Data (using PHP JSON MYSQL)
- Passing data from $ajax call to highcharts
- Emulate hover on iPad chart
- how to show labels in right side in chart?
- How to draw a Highcharts in opened modal window by using ui-bootstrap directive?
- legend size in Highcharts under ruby on rails
- Legend for each point in column chart in highcharts
- Is it possible with Chart js or which chart Library can provide this type of chart?
- Have an issue with JavaScript, AJAX code displaying data
- How to add specific values to highchart
- Highcharts shared tooltip for line series and scatter plot not working
- some error will be printed in consoled when i export highcharts
- Highcharts not referenced error when using setOptions
- How to assign chart title as exporting filename?
- Is there a way to load data into Highstock without the use of PHP?
- how to split by hour in highcharts while using x-axis type date range
- set individual color for each bar in bar chart using highcharts
- Highcharts Angular update chart with new options - including linked series
- Highmaps Flight Routes add arrows
- Highchart (basic line chart) which can have multiple values vs x axis?
- Apply Background Image to A Column
- Highcharts change look of tooltip
- Alternatives to Highcharts for datasets with 10k data points?
- Highcharts spline chart, display summed by week, month?
- Highmaps downloadXLS() issue with MacOS Safari
- HighCharts - set minimum Tick Interval
- Highcharts shared tooltip making a percentage difference between series