简体   繁体   中英

Chartjs - Stacked bar chart blocking other values

My problem is that chart js is rendering the bar chart based on the order defined on the dataset. As you can see below, the values at index 0 of the arrays are 2500 and 1000 . Since the 2500 was passed first, this will block the bar chart of the 1000 value.

https://jsfiddle.net/6bjy9nxh/352/

var barData = {
labels: ['Italy', 'UK', 'USA', 'Germany', 'France', 'Japan'],
datasets: [
    {
        label: '2010 customers #',
        fillColor: '#382765',
        data: [2500, 1902, 1041, 610, 1245, 952]
    },
    {
        label: '2014 customers #',
        fillColor: '#7BC225',
        data: [1000, 1689, 1318, 589, 1199, 1436]
    }
]

As Per the example of Chartjs for Stacked bar chart stacked: true for both xAxes and Axes

var barData = {
    labels : ['Italy', 'UK', 'USA', 'Germany', 'France', 'Japan'],
    datasets : [{
        label : '2010 customers #',
        backgroundColor : '#382765',
        data : [2500, 1902, 1041, 610, 1245, 952]
    }, {
        label : '2014 customers #',
        backgroundColor : '#7BC225',
        data : [1000, 1689, 1318, 589, 1199, 1436]
    }]
};

var context = document.getElementById('clients').getContext('2d');
var clientsChart = new Chart(context, {
    type : 'bar',
    data : barData,
    options : {
        scales : {
            xAxes : [{
                stacked : true,

            }],
            yAxes : [{
                stacked : true
            }]
        }
    }
});

This may help you. Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM