Partial broken highchart when using with AlpineJS V3 #2029
-
Hello together I need your help!I'm working on a project where I use a combination of Highchart and AlpineJS. First of all my solution worked with AlpineJS V2 but not properly after the V3 migration. When I call a function like Here is a part of the important code.Alpine.data("highchart", () => ({
chart: null,
init() {
this.chart = Highcharts.chart(this.$refs.chart, {
series: [
{
data: [
[1016060400000, 105],
[1016146800000, 185],
[1016406000000, 145],
[1016492400000, 100]
]
}
]
})
},
addSeries() {
this.chart.series[0].remove()
this.chart.addSeries({
data: [
[1016060400000, 100],
[1016146800000, 0],
[1016406000000, 125],
[1016492400000, 100],
[1016578800000, 120]
]
})
}
})) Steps to reproduce the problem:
Codesandbox example with AlpineJS V3 not working as expectedhttps://codesandbox.io/s/broken-highcharts-with-alpinejs-v3-orusz Codesandbox example with AlpineJS V2 working as expected.https://codesandbox.io/s/working-highcharts-with-alpinejs-v2-puc5f I'm out of ideas. I hope somebody can help me. Greetings |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This should be a working version for V3: https://codesandbox.io/s/broken-highcharts-with-alpinejs-v3-forked-dlx8h?file=/index.html The reason is that in V2, only literal objects and arrays were properly reactive. The Alpine reactivity is based on javascript object called proxies. IN v3, all object became reactive and those libraries often don't work smoothly with javascript proxy. |
Beta Was this translation helpful? Give feedback.
This should be a working version for V3: https://codesandbox.io/s/broken-highcharts-with-alpinejs-v3-forked-dlx8h?file=/index.html
The reason is that in V2, only literal objects and arrays were properly reactive. The Alpine reactivity is based on javascript object called proxies. IN v3, all object became reactive and those libraries often don't work smoothly with javascript proxy.
Moving the chart object outside of the returned Alpine data will do the trick