Chartjs-Counting string to plot a graph using chart.js and angular

0👍

You need to add a labels array to the scale and set the type to category to use string data:

const options = {
  type: 'bar',
  data: {
    labels: ["Earthquake", "Tornade", "Flood"],
    datasets: [{
      label: '# of Votes',
      data: ['Paris', 'Berlin', 'London'],
      backgroundColor: 'pink'
    }]
  },
  options: {
    scales: {
      y: {
        type: 'category',
        reverse: true,
        labels: ['', 'London', 'Paris', 'Berlin']
      }
    }
  }
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.1/chart.js"></script>
</body>

Leave a comment