[Chartjs]-Problem with multiple datasets in chart.js

1๐Ÿ‘

I was able to get it working with this code:

var graphData = {
    labels: ['Publication 1', 'Publication 2'],
    datasets: [{
      label: 'Impressions',
      data: [30000, 40000],
      backgroundColor: [
        "#971317",
        "#0b72ba"
      ],
    }, ]
  };

var ctx_webbanner_300x600 = document.getElementById('chart_webbanner_300x600').getContext('2d');

var chr = new Chart(ctx_webbanner_300x600, {
    data: graphData,
    type: 'bar',
    options: {
        scales: {
                yAxes: [{
                    display: true,
                    ticks: {
                        beginAtZero: true   // minimum value will be 0.
                    }
                }]
            }
                }
  });

This is based on what I found here Setting specific color per label in chart.js and here How to set max and min value for Y axis โ€“ which overcame a problem where the scale was starting at the lowest value in my data set.

Leave a comment