Search code examples
javascripthtmlvue.jschartsapexcharts

Bind different series in apex chart using vue.js for


I'm trying to creare N different bar chart using a for in Vue.js, but obviously in this way I'm creating N chart with the same data series. I want to create this N chart binding different series in each chart. I tried this way:

<apexchart type="bar" height="100%" :options="chartOptionsRealTime" :series="seriesRealTime[0]"></apexchart>

with series like:

seriesRealTime: [{
            name: 'first',
            data: [2.3, 3.1, 4.0, 10.1, 4.0, 3.6, 3.2, 2.3, 1.4, 0.8, 0.5, 0.2]
        },
        {
            name: 'second',
            data: [2.3, 3.1, 4.0, 10.1, 4.0, 3.6, 3.2, 2.3, 1.4, 0.8, 0.5, 0.2]
        },
        {
            name: 'second',
            data: [2.3, 3.1, 4.0, 10.1, 4.0, 3.6, 3.2, 2.3, 1.4, 0.8, 0.5, 0.2]
        }],

but :series="seriesRealTime[0]" doesn't work.

I want to create the firs chart with the series named "first", the second with the series named "second", ecc... Thre is a way to solve it?


Solution

  • You can see in documentation https://apexcharts.com/docs/options/series/

    Accepts an array of [name, data] object...

    So you need to pass an array

    <apexchart type="bar" height="100%" :options="chartOptionsRealTime" :series="[seriesRealTime[0]]"></apexchart>