score:4
you can provide a labels
array padded with empty strings to the required length, e.g. 15.
this will ensure a consistent number of categories on the axis, and thus ensure that the bars will stay the same width and left-aligned even when there are less bars (fiddle).
(if you like, you can also pad the data
array with 0
's for consistency, but it's not necessary - the labels
array is what determines the axis looks like.)
var data = [12, 19, 3, 5, 2];
var labels = ["a", "b", "c", "d", "e"];
for (var i = labels.length; i < 15; i++) {
labels.push("");
}
var ctx = document.getelementbyid("mychart");
var mychart = new chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'count',
data: data
}]
},
options: {
scales: {
yaxes: [{
ticks: {
beginatzero: true
}
}]
}
}
});
Source: stackoverflow.com
Related Query
- ChartJs bar chart - keep bars left instead of equally spread across the width
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- All the bar in bar chart stays at left with very little width
- Chart JS horizontal bar chart width of bars and the chart
- chartjs bar chart align the legend to left position
- Border radius for the bar chart in ChartJS
- Grouping the object by key for Chartjs bar chart
- How to make bar chart animation where all bars grow at the same speed?
- ChartJS bar chart fixed width for dynamic data sets
- Chart.js bar chart mouse hovering highlights all the datasets instead of just the selected one
- ChartJS bar chart - trigger hover even when the cursor is outside of the bar
- Display Bar chart values in the graph - ChartJS
- Chart.js: Reverse bar chart with regular bars (Bottom to top instead of top to bottom)
- Can the colors of bars in a bar chart be varied based on their value?
- Stacked Bar chart fixed width bar chart issue - Chartjs
- How to show the chartjs bar chart data values labels as text?
- How to prevent empty bars from taking up width in Chart.js bar chart
- Bar chart (chart.js) with only 2 points does not show one of the bars
- How can I move chartJs legend left side and change the width and Hight of the chart?
- ChartJS - would like to create a mixed chart with horizontal Bar and a dot to represent the answer from the current user
- ChartJS vertical bar chart - measure percentage of the data in each column based on a specified max
- Chart.js Change color of the values *inside* the bars of a Bar chart
- Chart.js stacked bar chart text on top of the stacked bars
- chartjs add dots to bars in grouped bar chart
- how to highlight the bars in stacked bar chart of chart.js on clicking a legend
- How to keep side bars in Chartjs bar graph from clipping?
- How do you get the width of a datalabel from the Chartjs plugin after the chart animates?
- react-chart-js-2 keep bar width no matter what the number of bar is
- ChartJS align bars to left instead of center
- ChartJS Bar chart with time scale - Bars overlap with each other
More Query from same tag
- How to provide different labels in chart.js for toolbox and axis
- Chartjs - onAnimationComplete fires before the animation actually completes
- how to show several labels and data's in the chart.js similar to npmtrend website?
- ChartJS unique datasets per label
- Angular protractor tests timeout on pages containing Chart.js
- Vue watch not noticing changes on component prop
- Displaying two values in tooltip using chart.js
- Displaying line chart for multiple datasets using chart.js
- Javascript chart fills up the entire browser window
- How to hide Fields and Strike-through Legends when the data is empty or Zero in Pie/Polar/Doughnut Chart?
- How to plot Firebase data with Chartjs in angular
- chart.js increase value on click
- In bar chartjs report zero values are skipped so bars are invalid
- How to have custom colors in ng2-charts and chart.js according to data?
- ChartJS: Bar chart with axis ticks wider than categories
- Chartjs 2 scaling lots of data points
- Add new line in es6 inside a doughnut chart
- Chart JS: Always show tooltips in a multi dataset line chart
- Chart.js will not render using vue.js until window resizes
- Print pie chart in chartjs
- How to remove quotations from a dictionary in python
- Chart not rendering on ChartJS
- int Array with empty value
- Set Global Config on Angular Charts Not Working
- Remove Chart.js chart padding
- Dynamically updating time data in chart.js freezes the chart
- ChartJs - Adding padding after Y- Axis
- How to make y axis only integer scaling in ChartJS?
- Horizontal Stacked Bar with Gaps
- gradient background on radar chartjs