@if(isset($PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSource) && $PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSource->isNotEmpty())
    <div id="EChartPocetKontrolPodlaEmisnehoSystemuVozidla" style="height:400px"></div>

    @push('scripts')
        <script type="text/javascript">
            $(document).ready(function () {
                const EChartPocetKontrolPodlaEmisnehoSystemuVozidla = echarts.init(document.getElementById('EChartPocetKontrolPodlaEmisnehoSystemuVozidla'), 'macarons');

                window.addEventListener('resize', function () {
                    EChartPocetKontrolPodlaEmisnehoSystemuVozidla.resize();
                });

                EChartPocetKontrolPodlaEmisnehoSystemuVozidla.setOption({
                    backgroundColor: 'transparent',
                    grid: {
                        height: 200,
                        top: 'auto',
                    },
                    legend: {
                        show: true,
                        type: 'plain',
                        align: 'right',
                        right: 0,
                        top: 60,
                        orient: 'vertical',
                        zlevel: 100,
                    },
                    tooltip: {
                        trigger: 'item',
                    },
                    toolbox: {
                        show: true,
                        orient: 'horizontal',
                        top: 0,
                        right: 0,
                        zlevel: 100,
                        feature: {
                            saveAsImage: {
                                type: 'png',
                                name: 'pek-pocet-kontrol-podla-emisneho-systemu-vozidla',
                                backgroundColor: 'white',
                                show: true,
                                title: 'Uložiť ako obrázok',
                            },
                            restore: {
                                show: true,
                                title: 'Obnoviť',
                            },
                        },
                    },
                    series: [{
                        type: 'pie',
                        radius: ['30%', '70%'],
                        center: ['30%', '40%',],
                        itemStyle: {
                            borderRadius: 10,
                            borderColor: '#fff',
                            borderWidth: 2,
                        },
                        startAngle: 15,
                        encode: {
                            itemName: 'label',
                            value: 'pocet',
                        },
                        animation: true,
                        animationType: 'scale',
                        animationEasing: 'elasticOut',
                        animationDelay: function (idx) {
                            return Math.random() * 400;
                        },
                        label: {
                            show: true,
                            position: 'outside',
                            rotate: false,
                        },
                        datasetIndex: 1,
                    }],
                    dataset: [
                        {
                            dimensions: [
                                {
                                    name: 'emisny_system',
                                    type: 'ordinal',
                                },
                                {
                                    name: 'label',
                                    type: 'ordinal',
                                },
                                {
                                    name: 'pocet',
                                    type: 'number',
                                }
                            ],
                            source: @json($PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSource ?? []),
                        },
                        {
                            transform: [
                                {
                                    type: 'sort',
                                    config: {
                                        dimension: 'emisny_system',
                                        order: 'asc',
                                    },
                                }
                            ],
                        }
                    ],
                });
            });
        </script>
    @endpush
@else
    <p class="h4 text-center text-muted">Nie sú k dispozícii žiadne údaje...</p>
@endif
