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.

stacked bar chart no longer working

See original GitHub issue

I saw https://github.com/jerairrest/react-chartjs-2/issues/220 that suggested adding both the stack attribute to each data column and stacked: true to the axes objects but for some reason this is broken for me

Using the same data in jsfiddle and the original chartjs library does show stacked bars but with this library it doesn’t

My input data for this is:

const colors = ['#004876', '#0063a0', '#007ecc', '#0093ee', '#82caf8', '#c8e6f4'];
const options = {
    layout: {
      padding: {
        bottom: 0,
        top: 0
      }
    },
    scales: {
      xAxes: [{
        stacked: true,
        gridLines: {
          display: false
        },
      }],
      yAxes: [{
        stacked: true,
          }],
    },
        responsive: true,
          legend: {
            display: true,
            position: 'right',
            labels: {
              fontColor: '#91929b',
              padding: 20
            }
          }
        };
const chartData = {
  labels: ["08-2018", "09-2018", "10-2018", "11-2018"],
  datasets: [{
      label: 'Air',
      data: [20000, 10000, 2000, 25000],
      stack:'1',
      backgroundColor: colors[0],
      borderWidth: 0
    },
    {
      label: 'Express',
      stack: '2',
      data: [20000, 20000, 2000, 25000],
      backgroundColor: colors[1],
      borderWidth: 0
    },
    {
      label: 'LCL',
      data: [5000, 5000, 20000, 25000],
      backgroundColor: colors[2],
      borderWidth: 0,
      stack: '3'
    },
    {
      label: 'FTL',
      data: [20000, 10000, 12000, 25000],
      backgroundColor: colors[3],
      borderWidth: 0,
      stack: '4',
    },
    {
      label: 'LTL',
      data: [20000, 5000, 10000, 25000],
      backgroundColor: colors[4],
      borderWidth: 0,
      stack: '5',
    },
    {
      label: 'FCL',
      data: [5000, 10000, 5000, 25000],
      backgroundColor: colors[5],
      borderWidth: 0,
      stack: '6',
    },
  ]
};

class App extends Component {
 
  render() {
      return ( <div className = "App" >
      <header className = "App-header" >
      <div>
        <Bar 
        data={chartData}
        options={options}
        width={700}
        height={350} />
        </div>
      </header> <
      /div>
    );
  }
}

The resulting chart with this library looks like this: Screenshot from 2019-03-27 14-05-49

while the same code in JSFiddle looks like this: https://jsfiddle.net/tbLv0nf4/5/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

14reactions
mulraj208commented, Jul 26, 2019
<Bar data={barChartData} options={barChartOptions} />

const barChartData = { labels: [‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’], datasets: [ { label: ‘Active’, backgroundColor: ‘#a88add’, stack: ‘2’, data: [30, 50, 20, 40, 50, 30, 20, 110], }, { label: ‘Banned’, backgroundColor: ‘#0cc2aa’, stack: ‘2’, data: [10, 0, 5, 15, 0, 4, 8, 8], }, ], };

const barChartOptions = { legend: { display: false, }, scales: { xAxes: [ { stacked: true, }, ], yAxes: [ { stacked: true, }, ], }, };

“chart.js”: “^2.8.0”, “react-chartjs-2”: “^2.7.6”,

This config works for me.

2reactions
cosmithcommented, Apr 30, 2019

This is working fine if you use the format as specified by chartjs (example here: view-source:https://www.chartjs.org/samples/latest/charts/bar/stacked.html)

You don’t need stack: x in your dataset either. Just stacked: true in your xAxes and yAxes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

100% Stacked Bar Is Not Working Properly - Excel Help Forum
From the ribbon, Insert>>Recommended Charts: On the "All Charts" tab, select Bar in the left-hand pane. Select the icon for 100% Stacked Bar...
Read more >
Solved: Stacked column chart is not working
Create below measure and add into to stacked column chart. If this post helps, then please consider Accept it as the solution.
Read more >
Several Data Interpretation Problems with Stacked Bar Chart ...
You may assume that stacked bar chart will work very well in most of data analytics scenarios. Well, the answer is no. Here...
Read more >
stack column does not stack data - Microsoft Community
Reservoir ‑ Damaged Impeller ‑ Magnet Assembly Hea... Reservoir ‑ Damaged ‑ Cracked 11 0 0 Reservoir ‑ Damaged ‑ Notes 7 0 0 Impeller ‑...
Read more >
stacked bar chart no longer working · Issue #388 - GitHub
I saw #220 that suggested adding both the stack attribute to each data column and stacked: true ... stacked bar chart no longer...
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