Chartjs-Chart.js : Not all points use defined colors

0👍

You shouldn’t define your colors as an array. Simply remove the squared brackets around them and it will work.

Please have a look at your amended code below.

new Chart('myChart', {
  type: 'line',
  data: {
    labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
    datasets: [{
        label: 'Sales Last Week',
        data: [12, 17, 7, 17, 23, 18, 38],
        backgroundColor: 'rgba(1, 161, 216, 0.2)',
        borderColor: 'rgba(1, 161, 216, 1)',
        borderWidth: 1
      },
      {
        label: 'Sales This Week',
        data: ['8', 17, 3, 17, 50, 10, 49],
        backgroundColor: 'rgba(1, 216, 128, 0.2)',
        borderColor: 'rgba(1, 216, 128, 1)',
        borderWidth: 1
      }
    ]
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart" height="100"></canvas>

Leave a comment