score:3
Accepted answer
This behaviour is fixed in v3 of the lib
var leftdata = {
labels: [0, 1, 2, 3, 4, 5],
datasets: [{
label: "A",
backgroundColor: 'rgba(0, 0, 255, 0.5)',
data: [12, 19, 3, 5, 1],
xAxisID: "A"
},
{
label: "B",
backgroundColor: 'rgba(0, 255, 0, 0.5)',
data: [14, 19, 6, 2, 4],
xAxisID: "B"
}
]
};
var rightdata = {
labels: [0, 1, 2, 3, "4", 5], // the #4 being a string is the only difference
datasets: [{
label: "A",
backgroundColor: 'rgba(0, 0, 255, 0.5)',
data: [12, 19, 3, 5, 1],
xAxisID: "A"
},
{
label: "B",
backgroundColor: 'rgba(0, 255, 0, 0.5)',
data: [14, 19, 6, 2, 4],
xAxisID: "B"
}
]
};
var options = {
scales: {
A: {
display: false,
barPercentage: 1.25,
ticks: {
max: 4
},
position: 'bottom'
},
B: {
display: false,
stacked: true,
offset: true,
barPercentage: 1.25,
position: 'bottom',
ticks: {
max: 4
}
},
x: {
display: true,
ticks: {
autoSkip: false,
max: 5
}
},
y: {
id: "bar-y-axis1",
ticks: {
beginAtZero: true
}
}
}
};
var leftctx = document.getElementById("topcanvas").getContext("2d");
new Chart(leftctx, {
type: 'bar',
data: leftdata,
options: options
});
var rightctx = document.getElementById("bottomcanvas").getContext("2d");
new Chart(rightctx, {
type: 'bar',
data: rightdata,
options: options
});
<div class="grid">
<canvas id="topcanvas"></canvas>
<canvas id="bottomcanvas"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.2.0/chart.js" integrity="sha512-opXrgVcTHsEVdBUZqTPlW9S8+99hNbaHmXtAdXXc61OUU6gOII5ku/PzZFqexHXc3hnK8IrJKHo+T7O4GRIJcw==" crossorigin="anonymous"></script>
</div>
Source: stackoverflow.com
Related Query
- Why are these 2.9 ChartJS bar charts different?
- chartjs - how to set the order in which the different charts are displayed
- Different color for each bar in a bar chart; ChartJS
- How to modify bar width in Chartjs 2 bar charts
- How do I make line charts overlay over bar charts in chartjs
- Why chart.js charts are not plotting data in Safari (works in Chrome)
- In bar chartjs report zero values are skipped so bars are invalid
- How to retain spacing between bars for two different bar charts in Chart.js 2
- How can I load multiple Chartjs charts with different data on the same page?
- Chartjs tooltip anchor point position on bar charts
- Rounded corners on chartJS v.2 - bar charts (with negative values)
- Why are my two charts repeating the same label?
- Why are the chartjs tooltip labels always showing the first x-axis label?
- Chartjs with Typescript: The types of 'interaction.mode' are incompatible between these types
- When I added a funnel chart to chartjs all the charts are load compressed until resize page
- Chartjs v2.7 - combo chart with time-series (financial) data; bar width's are irregular
- Grouped bar charts each group different level in chart.js
- chartjs display data in one bar line with 3 different data sets in 3 different colors
- Why is chartjs treating these arrays differently?
- Edit styles for axes in ChartJS bar chart, when gridlines are hidden
- Having different colors per bar with angular charts chart.js v2
- Smallest values are invisible in ng2-charts bar charts
- multiple chartjs charts with the same configuration but different data
- Chartjs doc examples are lightning fast but same code is slow when reproducing
- Different color for each bar in a bar graph in ChartJS and VueJS
- Merge two objects with different keys in chartjs bar
- Why the bar are not aligned the y axis
- Angular 4: Different color for bar in bar chart dynamically using ChartJS
- ChartJS Line Charts - remove color underneath lines
- Chartjs Bar Chart showing old data when hovering
More Query from same tag
- Responsive Chart.js Canvas barplot height?
- Connecting points between missing data in chart.js
- ChartJs - pie chart not showing
- Fill between two lines Chartjs
- Chart.js: How can a line series (out of many) change line color and thickness upon mouse hover?
- Legend color not working with randomly generated background colors in chartjs pie chart
- Chart.js legend alignment left side
- ChartJS - ignore labels
- ChartJS v2: Scale value at click coordinates (time scale)
- Second yAxes values not charting correctly with Chart.js
- Update data when pressing submit in chartjs in vuejs
- Why is my dependency injection not working in Angular?
- Chart.js not working - Uncaught RefernceError:
- angular-chart.js not rendering any chart
- creating a chart.js scatter graph with variables for data
- Chart.js V2 line chart missing point
- JavaScript Chart.JS - Custom tooltips to add description of specific data point when hovering
- JQuery Line Chart's X Axis not display in ASP.NET, C#, SQL Server
- Refreshing scope variable not working with scope function
- Chartjs-plugin: How to add a different color to each label?
- Chartjs: customise legend based on background color
- Chart.js with Angular component - Type 'string' is not assignable to type 'ChartTitleOptions | undefined'
- Stacked Group Bar from Chart.js : Can I give each stack group a unique color?
- Want only line not area under it in chart js
- Dynamic dataset from MySQL query with Chart.js
- NPM module doesn't work with Webpack 3 but works with vue-cli3 which based on Webpack 4
- Chart.js - PieChart defined background color for specific dataset element
- ChartJs - Labelling minimum and maximum value of the Y Axis
- ChartJS dynamic label
- In chart.js , change color of chart by clicking button