score:2
Accepted answer
to have the additional labels aligned with the stack group bars, you can define the option categorypercentage: 1
on each dataset
.
for further information, consult the chapters dataset configuration and barpercentage vs categorypercentage of the chart.js bar documentation.
further you'll have to define several x-axes as shown in your amended code below.
new chart('c', {
type: 'bar',
data: {
labels: ["1.1.2021", "2.1.2021"],
datasets: [{
label: 'first time visitor england',
data: [10, 3],
stack: "first-time-visitors",
backgroundcolor: "#f5a0a7",
categorypercentage: 1
},
{
label: 'repeating visitors england',
data: [20, 6],
stack: "repeat-visitors",
backgroundcolor: "#e75177",
categorypercentage: 1
},
{
label: 'first time visitor sweden',
data: [7, 0],
stack: "first-time-visitors",
backgroundcolor: "#924565",
categorypercentage: 1
},
{
label: 'repeating visitors sweden',
data: [9, 16],
stack: "repeat-visitors",
backgroundcolor: "#2979a7",
categorypercentage: 1
}
]
},
options: {
tooltips: {
mode: 'x'
},
scales: {
xaxes: [{
ticks: {
display: false
}
},
{
type: 'category',
offset: true,
labels: ['first-time-visitors', 'repeat-visitors', 'first-time-visitors', 'repeat-visitors'],
gridlines: {
display: false
}
},
{
offset: true,
gridlines: {
display: false
}
}
],
yaxes: [{
ticks: {
beginatzero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.4/chart.min.js"></script>
<canvas id="c" width="400" height="200"></canvas>
Source: stackoverflow.com
Related Query
- ChartJs - stacked bar chart with groups - how to create second x-axis with stack id
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- Create stacked bar chart with a single dataset per stack
- How do I create a stacked horizontal bar chart with Chart.js in React?
- How can I create a stacked bar chart with Charts.JS that displays relative rather than absolute values?
- Chartjs v3 overlap stacked bar chart with groups
- How to create stacked bar chart using react-chartjs-2?
- How to display inline values in a stacked bar chart with Chart.js?
- How to create chartjs chart with data from database C#
- How to create Bar chart that gets updated from new ajax requests with ChartJS?
- Chart.Js how to hide datapoints with "0" value in Stacked Bar Chart
- How do I create stacked chart with Chart.js version 2.0.0-beta
- Stacked bar chart with chartjs with included values
- Unable to create Stacked Grouped Bar Chart with chart.js / react-chartjs-2 in React
- how to write labels along with data on top and bottom of each stack in bar chart
- ChartJS - would like to create a mixed chart with horizontal Bar and a dot to represent the answer from the current user
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- how to create a bar chart with php data variables
- ChartJS 2.7.3 stacked bar chart with overlap
- how to highlight stack bar in ChartJS with onclick
- Draw stacked horizontal bar chart with Average line using ChartJS
- How to configure Chartjs Bar Stacked Chart in Laravel 8
- How to display a progress over time in one horizontally stacked bar with chartjs
- How to create rounded bar graph with Angular 7 and Chartjs (v2)
- How to create Stacked bar chart from JSON in chart.js
- How to create an animate-on-update Stacked Bar chart using Chart.js(or Chartist)?
- how to create bar chart with group and sam color for each group using chart.js?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs v2.0: stacked bar chart
More Query from same tag
- Chart.js not deploying properly on Heroku
- Change Chartjs Legend Icon Style
- Save graph as image after click link full script
- Charts.js legend more than view value
- Allowing Chart.js to work with jQuery Tabs
- chart.js plugins.register function with outer data
- JSON Data Assigning to Javascript Var Value
- Update the chart data from an array stored in a variable on button click
- Ionic + Angular Charts: Uncaught Error: Chart.js library needs to included
- Chart.JS: How can I only display data labels when the doughnut size is big enough for the text?
- How to show labels of dataset using chart.js
- How to align labels at same side chartjs React
- I'm getting the error "TypeError: Cannot read property 'extend' of undefined" when trying to import chartjs-plugin-datalabels
- Multiple charts not working chart.js
- Why is this bar chart using chart.js not rendering in react.js?
- Chart.js, PHP and JSON loop issue
- Acceptable Range Highlighting of Background in Chart.js 2.0
- In ChartJS is it possible to change the line style between different points?
- Vue watch not noticing changes on component prop
- How to add gradient background to Line Chart [vue-chart.js]
- chartkick chart.js change colour of axis and colour of axis title
- Chart.js v3 Fade Animation in delay
- Chart JS - single lines (points) tooltips
- How to change the time format displayed in the chart?
- How do I create a stacked horizontal bar chart with Chart.js in React?
- Live update the charts.js graph on a web page using json data received from a remote server
- How to ensure that a Chart.js line chart uses all space available on the y-axis?
- How to add an on click event to my Line chart using Chart.js
- ChartJS - Line Chart with different size datasets
- chart.js bar chart x-axis label disappeared