vue-apexcharts icon indicating copy to clipboard operation
vue-apexcharts copied to clipboard

Possible Unhandled Promise Rejection: TypeError: Cannot read property 'type' of undefined

Open happyDemon opened this issue 5 years ago • 9 comments

After updating my series (amount of series changed from 7 to 3) Fill.getFillColors tries to load the series with index '3', which doesn't exist anymore.

This happens on a bar chart

<template>
<apexchart width="100%" type="bar" height="350px" :options="graph.options" :series="grapSeries"></apexchart>
</template>

<script>
    export default {
        data () {
            return {
                graph: {
                    options: {
                        chart: {
                            id: 'vuechart-example',
                            background: '#fff',
                            brush: {
                                autoScaleYaxis: true,
                            },
                            stacked: true,
                        },
                        plotOptions: {
                            bar: {
                                columnWidth: '30%',
                                distributed: true
                            }
                        },
                        xaxis: {
                            categories: ['maa', 'din', 'woe', 'don', 'vri', 'zat', 'zon']
                        },
                        tooltip: {
                            custom: ({seriesIndex, dataPointIndex}) => {
                                const serie = this.graph.series[seriesIndex];
                                return `<div class="apexcharts-tooltip-series-group active" style="display: flex;"><div class="apexcharts-tooltip-text"><div class="apexcharts-tooltip-y-group"><span class="apexcharts-tooltip-text-label">${serie.name}: </span><span class="apexcharts-tooltip-text-value">${serie.time[dataPointIndex]}</span></div><div class="apexcharts-tooltip-z-group"><span class="apexcharts-tooltip-text-z-label"></span><span class="apexcharts-tooltip-text-z-value"></span></div></div></div>`;
                            }
                        }
                        colors: [({value, seriesIndex, w}) => {
                            if (typeof this.grapSeries[seriesIndex] === 'undefined') return '#000000';
                            return this.grapSeries[seriesIndex].color;
                        }]
                    }
                },
            }
        },
        computed: {
            grapSeries() {
                return this.$store.getters['reports/graph'];
            },
        },
    }
</script>

And every series looks like this:

{"name":"Visuals","client":"Cravat","color":"#999999","type":"column","data":[0,7,0,0,0,0,0],"time":["00:00:00","07:00:00","00:00:00","00:00:00","00:00:00","00:00:00","00:00:00"]}

happyDemon avatar Jun 25 '19 10:06 happyDemon

@junedchhipa do you have an idea?

happyDemon avatar Jul 02 '19 08:07 happyDemon

Please create a working codesandbox example - https://codesandbox.io/s/pwwz8009n0

junedchhipa avatar Jul 02 '19 09:07 junedchhipa

I have the same issue. But when I use type:'datetime' in the xaxis option, it does not show up.

But my xaxis is not a timeseries. Any workaround found yet?

saranyailla avatar Jul 03 '19 01:07 saranyailla

I have the same issue when re-rendering the charts. I can get rid of the error if I first remove the chart and render it again like this:

 document.getElementById('chart').innerHTML = '';
 var chart = new ApexCharts(
 document.querySelector("#chart"),
       options
 );

 chart.render();

mtfash avatar Aug 04 '19 11:08 mtfash

重新绘制图表时,我遇到相同的问题。如果先删除图表并再次渲染,就可以摆脱错误:

 document.getElementById('chart').innerHTML = '';
 var chart = new ApexCharts(
 document.querySelector("#chart"),
       options
 );

 chart.render();

This Perfectly solved my problem, Thanks a lot!

zhangjia avatar Feb 11 '20 15:02 zhangjia

Any updates on this? I have the problem only when I run a test in a react component that contains the chart.

DanielFerszt avatar May 03 '20 23:05 DanielFerszt

This happened for me when I had a null value in xaxis.

orkhi avatar Jul 21 '20 17:07 orkhi

If you use ApexCharts with Laravel, https://larapex-charts.netlify.app

php artisan optimize for me working Clear all cache in the application

lordjack avatar Oct 22 '21 02:10 lordjack

I fixed the issue by simple check if the array is undefined then return empty if not return the chart with my values data: salary[0] === undefined ? [] : salary

chadrackkyungu avatar Sep 15 '22 05:09 chadrackkyungu