Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

2.0 BAR (Stacked) Missing Every Other Label on X Axis

Open zahlprish opened this issue 10 years ago • 2 comments

Version 2.0 , Type: BAR

Bug with Missing labels on x-axis.

Hey all,

I am having an odd issue where my stacked bar graph is not displaying every other label on the X axis. (The black labels are showing, red is missing).

I know the labels exist as they do appear when hovered over.

missing_bar_labels

Relevant chart code:

    // Instanciate the bar graph.
    var myBarChart = new Chart(document.getElementById("activation-initiative-impact"),
        {
            type: 'bar',
            data: {
                labels: Object.keys(realData.activation_initiative_impact.data.datasets).map(function (key)
                        {
                            return realData.activation_initiative_impact.data.datasets[key].title;
                        }),
                datasets: [
                    {
                        label: "Total Activations",
                        backgroundColor: "rgba(193, 69, 123, .3)",
                        borderColor: "rgba(193, 69, 123, 1)",
                        borderWidth: 1,
                        data: Object.keys(realData.activation_initiative_impact.data.datasets).map(function (key)
                                {
                                    // If it less than one, mark it a zero.
                                    if(realData.activation_initiative_impact.data.datasets[key].total_activations < 1)
                                    {
                                        return 0;
                                    }
                                    else
                                    // Grab the value from within the array/object.
                                    {
                                        return parseInt(realData.activation_initiative_impact.data.datasets[key].total_activations);
                                    }
                                }),
                    },
                    {
                        label: "Total Events",
                        backgroundColor: "rgba(11, 143, 191, .3)",
                        borderColor: "rgba(11, 143, 191, 1)",
                        borderWidth: 1,
                        data: Object.keys(realData.activation_initiative_impact.data.datasets).map(function (key)
                                {
                                    // If it less than one, mark it a zero.
                                    if(realData.activation_initiative_impact.data.datasets[key].total_events < 1)
                                    {
                                        return 0;
                                    }
                                    else
                                    // Grab the value from within the array/object.
                                    {
                                        return parseInt(realData.activation_initiative_impact.data.datasets[key].total_events);
                                    }
                                }),
                    }
                ]
            },
            options: {
                tooltips: {
                    mode: 'label'
                },
                responsive: true,
                scales: {
                    xAxes: [{
                        stacked: true,
                    }],
                    yAxes: [{
                        stacked: true
                    }]
                }
            }
        });

zahlprish avatar Apr 29 '16 20:04 zahlprish

@zahlprish try turning auto skipping off for the x axis

in the x axis config:

{
  stacked: true
  ticks: {
    autoSkip: false
  }
}

etimberg avatar Apr 29 '16 20:04 etimberg

@etimberg Yep! Nailed it. Thanks a bunch!

zahlprish avatar Apr 29 '16 22:04 zahlprish