question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bar chart with Multiple grouped datasets

See original GitHub issue

I have to create the same graph as shown in the attached picture which I created on excel. I have following through the documentation and tried multiple times different approaches but couldn’t be succeeded in setting x-axis labels and values like in the attached picture. What am I doing wrong?

Here is my code which I tried but failed to set year wise total Expenditure and total Budget values which are grouped on codes “SC21106” and “SC21108”

var barChartData = {
  labels: [
    ["SC21106",
    "SC21108",],["2016",2017","2018","2019"]
  ],
  datasets: [
    {
      label: "Total Expenditure",
      backgroundColor: "Red",
      data: [300000000, 555555555,555555554,666666665]
    },
    {
      label: "Total Budget",
      backgroundColor: "pink",
      data: [500000000, 77777555,566666654,666666665]
    },
  ]
};

var chartOptions = {
  responsive: true,
  scales: {
    yAxes: [{
      ticks: {
        beginAtZero: true
      }
    }]
  }
}

Target to achieve: image

P.S : I am new to Chart js and the code I tried has rough values. In short, I just want a chart js bar graph like the picture I attached.

Any help would be highly appreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stockiNailcommented, Jun 18, 2020

@ByteMates as @etimberg wrote (thanks!), there is a plugin which can do something close to what you want.

Anyway I spent some minutes to create a dedicated plugin to have the same representation of your picture. It’s not a generic plugin but something dedicated for this use case.

https://codepen.io/stockinail/pen/vYLyXop

bytemate

1reaction
etimbergcommented, Jun 17, 2020

@stockiNail has a good solution. https://github.com/sgratzl/chartjs-plugin-hierarchical also works. We are not planning on adding this functionality to the core library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Grouped Bar Charts | Tutorial by Chartio
Like a standard bar chart, the grouped bar chart is built for showing a distribution of data points or making comparisons across different...
Read more >
Grouped Bar Chart in Excel - How to Create? (10 Steps)
1. u003cbr/u003eu003cimg alt=u0022Grouped-Bar-Chart-Example-1.0.1u0022 src=u0022https://www.wallstreetmojo.com/wp-content/uploads/2019/08/Grouped-Bar-Chart ... 2. u003cbr/u003eu003cimg alt=u0022Grouped-Bar-Chart-Example-1.0.1.5u0022 src=u0022https://www.wallstreetmojo.com/wp-content/uploads/2019/08/Grouped-Bar-Chart ... 3. u003cbr/u003eu003cimg alt=u0022Grouped-Bar-Chart-Example-1.2.0u0022 src=u0022https://www.wallstreetmojo.com/wp-content/uploads/2019/08/Grouped-Bar-Chart ...
Read more >
Grouped bar with multiple series : Chart Gallery - FusionCharts
The multi-series 2D bar chart is used for comparing data from multiple datasets. It is also used to analyze data grouped in sub-categories....
Read more >
Grouped Bar Chart - Data Viz Project
Grouped Bar Charts are used when two or more data sets are displayed side-by-side and grouped together under categories on the same axis....
Read more >
How to create a grouped bar chart - Datawrapper Academy
The bar chart is probably the most all-rounder chart type out there. But sometimes, your bars fall into categories (like continents, regions or ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found