Multiple times running function chartjs

by abhishek_soni

HTML

<canvas id="myChart" width="200" height="200"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.0/chart.min.js" integrity="sha512-asxKqQghC1oBShyhiBwA+YgotaSYKxGP1rcSYTDrB0U6DxwlJjU59B67U8+5/++uFjcuVM8Hh5cokLjZlhm3Vg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2"></script>

JavaScript

var ctx = document.getElementById('myChart').getContext('2d');

let i = 0,
  j = 0,
  k = 0;

var myChart = new Chart(ctx, {
  type: 'line',
  data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],

    }]
  },
  options: {
    animation: false, // this reduces it by half as for all animations it's renders twice
    elements: { // this reduces it by number of options, as this is applied after the default options are run.
      line: {
        borderWidth: 1,
        borderColor: function() {
          ++i;
          console.log('why this bordercolor running this many times : ', i)
          return 'green'
        }
      },
    },
    responsive: function() {
      k++;
      console.log('why this option running this many times : ', k)
      return false
    },
    maintainAspectRatio: false,
    scales: {
      y: {
        beginAtZero: function() {
          j++;
          console.log('why this scale running this many times : ', j)
          return true
        }
      }
    }
  }
});