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
- Chart not rendering with pug/jade and nodejs
- text inside the bar - chart.js
- Struggling with dynamic data
- Chart.js Line graph y-axis not starting from 0
- Unable to get the expected legend shown in chart js
- Chart js sum of grouped bars
- How to set minimum height for bars graph
- Angular Chart.js, how to remove series?
- ChartJs - pie chart not showing
- set scroll on bar chart in chartjs
- How to use Chart.js with Typescript without getting assignable errors?
- Changing grid color in radar chart
- Loading or Activating ChartJS on Load
- Return values from nested array
- Can't apply options of datalabels chartjs plugin in Vue
- Type error in using chartjs and tc-angular-chartjs
- Incorrect chart displayed using chart js
- Chart.js jQuery dropdown selected values
- How can I skip data/labels in a period of time in Chartjs?
- setInterval on my Doughnut.js
- Chart.js rotating x-axis text labels
- Change legend style from bar to line chart.js 2.4.0
- Javascript highcharts code similar to image
- Change background color of label Chart.js
- How to assign different background colors to chart.js pie chart data set?
- Creating multiple charts based on dictionary length
- Chart.js and right side free space
- populate chartjs ajax servlet
- Chart.js pie chart to display "No Data" if the datasets are empty
- chart js, loading data dynamically