barPercentage & categoryPercentage do not put the bars right next to each other
In Chart JS documentation, barPercentage is said to put the bars right next to each other if set to 1.0 since it will take the whole category width.

However, I get this

I want no spacing/padding between the two bars. Note: this occurs only if categoryPercentage is equal to anything other than 1.0. I don't want to set categoryPercentage to 1.0 because I don't want the category to take full width and I want the bars to be thin.
Live demonstration: http://codepen.io/anon/pen/KgoKyg?editors=0010
@KHKKhalid i tried to look at your codepen but it is infinitely refreshing the page :/
I have no clue why this would happen. Here's the code anyway
var ctx = document.getElementById("myChart");
var chart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['X', 'Y'],
datasets: [{
label: 'Magnitude',
data: [1, 2],
backgroundColor: ['yellow', 'orange']
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
fixedStepSize: 5,
max: 15,
min: 0
},
gridLines: {
color: 'black',
zeroLineColor: 'black',
zeroLineWidth: 4
}
}],
xAxes: [{
gridLines: {
display:false,
zeroLineWidth: 4,
},
barPercentage: 1.0,
categoryPercentage: 0.1
}]
}
}
});
Does this work for you http://codepen.io/khalidahmedshalabi/pen/mAxJmp
For anyone facing this issue, I figured out a workaround, set categoryPercentage and barPercentage to 1.0 (this will put bars next to each other), then keep pushing empty data to your graph (transparent color, 0 values) at the front and back (to make the bars centralized) of your graph until you reach the thickness you want.
Here's a snippet of my project that sorta illustrates how it works
var AddEmptyDataToChart = function ()
{
if(bars_shown < 4 * MAX_TABS)
{
var i;
var data_count_on_each = Math.ceil(((4 * MAX_TABS) - bars_shown) / 2);
// Add at the beginning and at the end
for(i = 0; i < data_count_on_each; i ++)
{
// Beginning
labels.push(" ");
values.push(0);
bgcol.push("rgba(0, 0, 0, 0.0)");
bordercol.push("rgba(0, 0, 0, 0.0)");
// End
labels.unshift(" ");
values.unshift(0);
bgcol.unshift("rgba(0, 0, 0, 0.0)");
bordercol.unshift("rgba(0, 0, 0, 0.0)");
}
}
};
I am facing the same issue in horizontal bar chart. Is there any fix for it?
@ennyta check the workaround I posted above.
It works as documented, you are just misunderstanding what a category is. 1 label = 1 category.
You can also split the data to individual datasets (so the bars can be in same category): https://codepen.io/kurkle/pen/oNgoNjR?editors=0010