text: import { LightningElement } from 'lwc';
  import { loadScript } from 'lightning/platformResourceLoader';
  import chartjs from '@salesforce/resourceUrl/chart';
  
  const generateRandomNumber = () => {
      return Math.round(Math.random() * 100);
  };
  
  export default class LibsChartjs extends LightningElement {
      error;
      chart;
      chartjsInitialized = false;
  
      config = {
          type: 'doughnut',
          data: {
              datasets: [
                  {
                      data: [
                          generateRandomNumber(),
                          generateRandomNumber(),
                          generateRandomNumber(),
                          generateRandomNumber(),
                          generateRandomNumber()
                      ],
                      backgroundColor: [
                          'rgb(255, 99, 132)',
                          'rgb(255, 159, 64)',
                          'rgb(255, 205, 86)',
                          'rgb(75, 192, 192)',
                          'rgb(54, 162, 235)'
                      ],
                      label: 'Dataset 1'
                  }
              ],
              labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue']
          },
          options: {
              responsive: true,
              legend: {
                  position: 'right'
              },
              animation: {
                  animateScale: true,
                  animateRotate: true
              }
          }
      };
  
      renderedCallback() {
          if (this.chartjsInitialized) {
              return;
          }
          this.chartjsInitialized = true;
  
          loadScript(this, chartjs)
              .then(() => {
                  const canvas = document.createElement('canvas');
                  this.template.querySelector('div.chart').appendChild(canvas);
                  const ctx = canvas.getContext('2d');
                  this.chart = new window.Chart(ctx, this.config);
              })
              .catch((error) => {
                  this.error = error;
              });
      }
  }
  