score:3
Accepted answer
You can divide the "categoryPercentage" into as many columns as possible and multiply by the number of columns in the current dataset
https://jsfiddle.net/qrwvvtxs/2/
var barChartData1 = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: 'Dataset 1',
data: [3,2,7,4,5,7,6]
}, {
label: 'Dataset 2',
backgroundColor: "#faa",
data: [11,13,21,13,16,21,18]
}]
};
var barChartData2 = {
labels: ["January"],
datasets: [{
label: 'Dataset 1',
data: [6]
}, {
label: 'Dataset 2',
backgroundColor: "#faa",
data: [11]
}]
};
var ctx1 = document.getElementById("canvas1").getContext("2d");
var ctx2 = document.getElementById("canvas2").getContext("2d");
var myBar1 = new Chart(ctx1, {
type: 'bar',
data: barChartData1,
options: {
responsive: true,
scales: {
xAxes: [{
barPercentage: 1,
categoryPercentage: 0.5 / 10 * barChartData1.datasets[0].data.length
}],
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
var myBar2 = new Chart(ctx2, {
type: 'bar',
data: barChartData2,
options: {
responsive: true,
scales: {
xAxes: [{
barPercentage: 1,
categoryPercentage: 0.5 / 10 * barChartData2.datasets[0].data.length
}],
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
<canvas id="canvas1"></canvas>
<canvas id="canvas2"></canvas>
Source: stackoverflow.com
Related Query
- ChartJS bar chart fixed width for dynamic data sets
- Chartjs - data format for bar chart with multi-level x-axes
- Set fixed label size for grouped bar chart in angular Chartjs
- Stacked Bar chart fixed width bar chart issue - Chartjs
- ChartJS not showing data for time series bar chart
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- ChartJS fails to render horizontal bar chart for timeseries data
- Chartjs Bar Chart showing old data when hovering
- Chartjs random colors for each part of pie chart with data dynamically from database
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- ChartJs bar chart - keep bars left instead of equally spread across the width
- Border radius for the bar chart in ChartJS
- ChartJS bar not showing up for simple data points
- Grouping the object by key for Chartjs bar chart
- Minimum value for x Axis doesn't work for horizontal bar chart | ChartJS
- ChartJS 2.6 - Bar chart fixed height scrollable-X
- Chart.JS: How can I only display data labels when the bar width is big enough for the text?
- ChartJS 2.9.4 can't overlay line data on Horizontal Bar chart
- Linear x axis for bar chart chartjs
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- Make chartjs pie chart wiyh dynamic data
- How to show the chartjs bar chart data values labels as text?
- Chartjs : Can I overwrite bar value on hover for every bar chart
- Dynamic data in bar chart not rendering React js
- Chartjs Bar Chart showing old data when hovering when use of ajax
- Chartjs - Stacked bar chart data order causes invisible other values
- ChartJS dynamic line chart ghosting back to old data when hovered on
- how to make chartjs columns smaller in width for bar chart?
- chartjs display data in one bar line with 3 different data sets in 3 different colors
- Two data sets with different time instances on the same ChartJs chart
More Query from same tag
- chart.js animation loading
- 【React chart.js】How to add multiple data to Radar chart using map function
- How to display data on hover inside doughnut chart in Angular Chart?
- Changing x axis labels in Chart.js line chart
- Angular using PrimeNG charjs problem with font colors
- Chart JS 2.x: How to show a tooltip in a timeline chart?
- Dynamically populating data into chart in Chart.js
- How to update Chartjs in Reactjs?
- Disable or hide YAixs of chart in chartJs
- Chart.js - draw an arbitrary point with tooltip
- How to display Json object in chart js consisting of lists created using Django rest framework in angular application
- How to adjust spaces between points in chart js?
- Dynamically changing chartjs tick colours
- How to show percentage (%) in chart js
- Chart.js not able to re-set data
- Using Chart.js with SvelteKit
- ChartJS options with Chartkick
- Chart js not display graph
- Drawing line chart in chart.js with json response
- How to prevent empty bars from taking up width in Chart.js bar chart
- When I added a funnel chart to chartjs all the charts are load compressed until resize page
- How to remove border from stacked column chart in Chartkick - Chart.js
- How to push array multidimesional in javascript
- Change point style in Chartjs via external event
- Chart.js - How to push a collection of array into dataset
- How to customize the title and tooltip in ux-chartjs?
- Angular 6 multiple dynamic Charts.js not showing
- chart.js plotting timeseries
- Chart Js doesn't update the values in the first load
- Horizontal Bar-Chart - angular-chart.js