Failed to load Highchart data into Laravel

Asked

Viewed 64 times

0

I’m trying to make a simple chart that displays the Daily Total Sales.

inserir a descrição da imagem aqui

<body>
<script src="{{asset('onboard/Scripts/highcharts.js')}}"></script>

<script>

                    const data = []
                    const total = []
                    @foreach($dashboard as $db)      
                        data.push( '{{ date("d/m/Y", strtotime($db->DATA)) }}')
                        total.push( '{{"R$ ".number_format($db->TOTAL, 2, ",", ".") }}')
                    @endforeach

                    const options = {
                    chart: {
                        type: 'bar',
                        renderTo: document.getElementById('chart')
                    },
                    title: {
                        text: "Dashboard"
                    },
                    subtitle: {
                    text: 'Vendas diarias'
                    },

                    xAxis: {
                    categories: data,
                    crosshair: true
                    },
                    yAxis: {
                    min: 0,
                    title: {
                        text: 'TOTAL'
                    }
                    },
                    tooltip: {
                        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                            '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
                        footerFormat: '</table>',
                        shared: true,
                        useHTML: true
                    },
                    plotOptions: {
                        column: {
                            pointPadding: 0.2,
                            borderWidth: 0
                        }
                    },
                    series: [
                        {   
                            name: data,
                            data:  total
                        },
                    ]
                    };

                    new Highcharts.Chart(options);

                </script>

I don’t know where the error is anymore not showing the column data.

1 answer

0


Normalized after passing date and total on the same variable as row 4 of the code below.

                const data = []
                const total = []
                @foreach($dashboard as $db)      
                    data.push( ['{{ date("d/m/Y", strtotime($db->DATA)) }}',{{$db->TOTAL}}])                      
                @endforeach

Browser other questions tagged

You are not signed in. Login or sign up in order to post.