Chartjs-Not understanding why chart js wont load

2👍

AFA I can see, the issue seems to be in the chart configuration and the data node is missing.
Without it, the chart doesn’t have data to show.

The code should be:

<div>
    <canvas id="item-listing-data" width="400" height="400"></canvas>
</div>

@push('scripts')
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>

        const ctx    = document.getElementById('item-listing-data').getContext('2d');

        const saleDataChart = new Chart(ctx, {
            type: 'line',
            data: { // <--- this was missing
              labels: @json($saleData['labels']),
              datasets: [{
                  label: 'Sale Data',
                  data: @json($saleData['data']),
                  fill: false,
                  borderColor: 'rgb(34, 67, 156)',
                  tension: 0.1
              }]
            }
          });
    </script>
@endpush

Leave a comment