Avatar of tonelm54
tonelm54
 asked on

ChartJS - Stacked Bar -> Not drawing any bars

Help, please :-S


Im trying to get a stacked bar chart working, but I get no bars shown when I try and build it. Im not really fussed at the moment if the data is right, as I can manipulate that, but Im totally stuck where Im going wrong and why my bars are not drawing at all.

<canvas id="chartJSContainer" width="300" height="150"></canvas>

<script>
    const ctx = document.getElementById('chartJSContainer');

    const myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            label: ["D1", "D2", "D3", "D4", "D5", "D6"],
            datasets: [
                {
                    label: 'Dataset 1',
                    data: [12, 19, 3, 5, 2, 3],
                    backgroundColor: 'rgba(255, 99, 132, 0.2)',
                    stack: 'combined',
                    type: 'bar'
                },
                {
                    label: 'Dataset 2',
                    data: [12, 19, 3, 5, 2, 3],
                    backgroundColor: 'rgba(54, 162, 235, 0.2)',
                    stack: 'combined',
                    type: 'bar'
                },
                {
                    label: 'Dataset 3',
                    data: [12, 19, 3, 5, 2, 3],
                    backgroundColor: 'rgba(75, 192, 192, 0.2)',
                    stack: 'combined',
                    type: 'bar'
                },
            ]},
        options: {
            plugins: {
                title: {
                    display: true,
                    text: 'Chart.js Bar Chart - Stacked'
                },
            },
            responsive: true,
            scales: {
                y: {
                    stacked: true
                }
            }
        }
    });

Open in new window

All I get:-


Is there any hints what Im doing wrong?

jQuery* chartjs

Avatar of undefined
Last Comment
tonelm54

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
tonelm54

ASKER
DOH!!, huge thank you though :-)

If I could ask another favour, any chance you can look at https://www.experts-exchange.com/questions/29227859/ChartJS-Annotation-plugin-not-drawing-box.html if possible as well please?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes