Closed pablosettecase closed 2 months ago
Hi @pablosettecase, thanks for reporting!
I believe that this chartOptions.value.series[0].data = newdata
is what you've tried out and it works as expected: https://stackblitz.com/edit/vue3-hightcharts-vue-b5qd87?file=src%2Fcomponents%2FMyChart.vue,src%2Fmain.js
By updating the chartOptions
ref, you update the chart configuration and the chart gets redrawn properly.
This is currently the recommended approach.
As an alternative (though not officially supported and recommended), you could access the Highcharts.Chart
instance (https://github.com/highcharts/highcharts-vue?tab=readme-ov-file#chart-object-reference) and perform all the methods listed here: https://api.highcharts.com/class-reference/Highcharts.Chart
But essentially, the exact same result can be achieved in 90+% of cases by just updating the chartOptions
, just as you suggested.
I'll still be available to support you with this, but I'm closing this issue as it's not a bug.
Thank you! Your code sample helped me update my code to clean it up. There is an important part that I missed in the docs in the npm page, that are also not in any of the sample code.
In the component I added:
import { Chart } from 'highcharts-vue'
and in the template I changed
<highcharts :options="chartOptions"></highcharts>
to
<Chart :options="chartOptions" ref="chart"></Chart>
When fetching data, I am now updating the series like you suggest:
chartOptions.value.series[0].data = newData
Intro
I have a simple Vue 3 app with a date picker and a Highcharts line plot. I'm using this library and was able to leverage the example code in these docs to create my line chart in Vue's composition API. My goal is to find the recommended way to update the entire series data. The example code in these docs only adds points to an existing ref array as far as I can tell.
Problem
After the user uses the date picker and a new data set is fetched, what is the recommended way to update the entire series data?
I have tried
chartOptions.series.data
chartOptions
by settingchartOptions.value.series[0].data = newdata
My Current Solution
Pop all the elements out of my data ref object and push each new data point in.
My Code
My code below shows my current solution, not my attempts that I mentioned. Any help is appreciated. Thank you.