score:3
Accepted answer
You can use closure in createDonatsChart functions. Set const as const originalData = [...data]
and then you can access to data in afterLabel callback (as example):
tooltips: {
callbacks: {
afterLabel: function(tooltipItem, data) {
const sexArray = originalData[tooltipItem['index']].sex
const precent = sexArray.reduce((a, b) => a + b, 0) // your calculation here
return '(' + precent + '%)';
}
}
}
See example in playground: https://jsfiddle.net/denisstukalov/upw6asjm/63/#&togetherjs=3CN0LJDjbl
Source: stackoverflow.com
Related Query
- Chartjs - Insert additional data into chart tooltip
- how to insert dynamic data from sql into chartjs stacked bar chart javascript
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- getting additional value fields from data source for dx.chartjs doughnut chart
- Insert value into a ChartJS with different data label
- Chartjs Bar Chart showing old data when hovering
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- ChartJS - Draw chart with label by month, data by day
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- show label in tooltip but not in x axis for chartjs line chart
- ChartJS add tooltip to a grouped bar chart
- chart js tooltip how to control the data that show
- Add all data in the tooltip of Chart JS
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Show data dynamically in line chart - ChartJS
- React ChartJS prevent new data from being added into state after it's redrawn?
- Chartjs - data format for bar chart with multi-level x-axes
- How to feed hour and minute data into chartJS
- Is it possible to combine two Y axes into a single tooltip with ChartJS 2?
- ChartJs line chart - display permanent icon above some data points with text on hover
- React ChartJS 2 : Get data on clicking the chart
- Parsing JSON data into Chart.js bar chart
- ChartJS bar chart fixed width for dynamic data sets
- Custom data in label on ChartJS pie chart
- How to create chartjs chart with data from database C#
- ChartJS version 3 how to add percentage to pie chart tooltip
- ChartJS - Adding legend title into tooltip title
- Missing Tooltip for some data points using chartjs
- Beginner using chart.js: having trouble display state full of data into a column chart using variables
More Query from same tag
- How to make a step line with charts.JS
- Which scenarios might make Chart.js's canvas element resize?
- Getting charts.js to read from Google Sheet JSON data
- How to change format of DateTime reading into chart.js chart?
- How to add padding between Graph and X/Y-Scale in chart.js?
- ChartJS: Show all tooltips with Total for Multi Pie chart
- Input data in german data format combined with ChartsJs
- Is it possible to add individual labels to Chart.JS bars?
- How to unregister chartjs-plugin-labels globally?
- Chart.js - Show new data on button click
- how to use chart.js with knockout.js to create dynamic charts
- Javascript get JSON into arrays, combine and use elsewhere
- Chartjs break line for axes tick labels text
- Remove Chart.js Gridline Overlap
- Chart.js doughnut text colors
- Disable display of x and y values on ChartJS
- chartjs bar chart filter using datetimepicker
- Chart.js Style bold on 1/one/certain label
- Why aren't my data points getting placed in the corresponding locations in my chart?
- How to extract ChartJs data and config properties
- Can't change color line with chart.js
- Add Text to Doughnut Chart - ChartJS
- Grouped bar charts, in chart.js
- Remove white space in ChartJS when value is null
- How to set vertical lines for new day on x-axis in ChartJS v3.x
- Chart.js - Bar chart: Add text after numbers when h:over a Bar
- Error says Chart is not defined
- How to decrease bottom width of triangle using line chart in chartJs?
- Chartjs doc examples are lightning fast but same code is slow when reproducing
- Chart is disappearing during # link