Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

64
Views
Display multiple labels using Chartjs

I want to display multiple labels in the graph that is being displayed in my application.

Link to Chartjs library

In the library, you can see that the bar chart has a single label, "My First Dataset", being displayed at the top of the graph. I want another label with the next colour.

Here's my code:

this.chartData = {
  labels: [
    ...labelList
  ],
  datasets: [
    {
      label: ['Digital Revenue', 'Standard Revenue'], //I want these two at the top
      data: [
        ...dataList
      ],
      backgroundColor: [
        'rgb(255, 99, 132)',  //using these two colours, but I am getting both values with a single colour
        'rgb(54, 162, 235)',
      ],
      hoverOffset: 4,
    },
  ],
};
this.chartConfig = {
  type: CHART_CONFIG.BAR_CHART,
  data: this.chartData,
  options: {},
};

this.myChart = new Chart(
  document.getElementById('myChart') as HTMLCanvasElement,
  this.chartConfig
);
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs