score:1
Accepted answer
It just works fine, the only thing that is different is that it seems like in v2 it defaulted to the point
mode while now it is using index
mode, if you change it back to point
it works as expected:
var options = {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'red'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
backgroundColor: 'blue'
}
]
},
options: {
plugins: {
tooltip: {
mode: 'point',
callbacks: {
beforeBody: (ttItems, x) => {
ttItems.forEach((ttItem) => {
console.log('BeforeBody: ', ttItem.datasetIndex, ttItem.dataIndex)
})
},
afterBody: (ttItems, x) => {
ttItems.forEach((ttItem) => {
console.log('AfterBody: ', ttItem.datasetIndex, ttItem.dataIndex)
})
}
}
}
},
scales: {
y: {
stacked: true
},
x: {
stacked: true
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.4.1/chart.js"></script>
</body>
Source: stackoverflow.com
Related Query
- Chart.js v3: Tooltip callback doesn't identify clicked dataset of stacked bar chart
- Chart JS attempt to stacked bar chart tooltip for only one dataset
- Create stacked bar chart with a single dataset per stack
- ChartJS: Highlight dataset in a stacked bar chart when hovering over the legend?
- ChartJS add custom tooltip to a stacked bar chart
- ChartJS - Horizontal Stacked Bar Chart Tooltip being cut off by Bottom of Canvas
- How to get clicked bar chart tooltip data?
- Chart.js dynamic dataset and tooltip on stacked bar
- chart.js 3 stacked bar chart - tooltip showing for zero values
- Chart JS Tooltip Currency Problem - Stacked Bar Chart
- How to assign values to different lables(legends) of my dataset of stacked bar chart
- chat,js stacked bar chart (make one dataset into stacked)
- Chartjs v2.0: stacked bar chart
- Horizontal stacked bar chart with chart.js
- Vertical stacked bar chart with chart.js
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Add DataSet Bar Chart - Chart.JS
- Click event on stacked bar chart - ChartJs
- ChartJS add tooltip to a grouped bar chart
- How to create stacked bar chart using react-chartjs-2?
- Hide empty bars in Grouped Stacked Bar Chart - chart.js
- How to display inline values in a stacked bar chart with Chart.js?
- ChartJs how to get from mulitiple dateset which dataset bar is clicked
- Chart js v2 tooltip callback line breaks
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Showing Percentage and Total In stacked Bar Chart of chart.js
- Stacked horizontal bar chart along total count with chart.js
- chart.js: Place tooltip for stacked bar charts on top of bar
- Stacked bar chart results in misaligned bars
- Multiple stacked bar chart using ChartJs
More Query from same tag
- How to make ChartJS not cut off tooltips?
- Chart js shows old chart data when hover
- Chartjs-node with canvas-prebuilt is still throwing 'Cairo not found' errors
- Chartjs: How to programatically remove (unhighlight or make inactive) all the active points on chart
- Extend bar chart on Chart JS 2 into a new type of Chart
- Updating chart.js based on selections from dropdown
- ChartJS does not display when using local Chart.js file
- How to adjust the Js Chart's label?
- Chart.js V2: Add prefix or suffix to tooltip label
- Using click event handler prevents tooltips from displaying on hover
- Meteor and ChartJS dynamically create a chart
- Render Chart.js on backend side ASP.NET
- Chartjs - Shift line plot to the right?
- The engine “node” is incompatible with this module when installing React-chartjs-2 Chart.js,
- chart.js streaming data plugin data format or config error
- chart.js - dynamically added chart makes previous ones disappear
- ChartJs: Loading fresh data to Chart
- Chart.js hidden property
- ChartJS - adding scroll to horizontal legend in Line chart
- Why is ChartJS skipping an xAxis label in this snippet?
- How to plot an equation using ChartJS?
- How do I refresh data from json-file with charts.js?
- How can i give the full Legend a background color in chart js?
- how to make chartjs columns smaller in width for bar chart?
- Dynamically set chart type with Angular Chart?
- Is it possible in chartjs to hide certain dataset legends?
- PrimeNG pie chart randomly displays, and displays on change of resolution
- Chart Js Line chart with fill on click with full information of its legend text
- Chart.js ng2-charts colors in pie chart not showing
- Chart.js chart.update() method is not doing anything