score:1
Accepted answer
since the pie chart defines an array of backgroundcolor
for each dataset in it and the function is called for each datalabel on the chart, you will need a way to tell which color in the array the function should use, probably using the index will do the trick.
try something like this:
return context.dataset.backgroundcolor[context.dataindex];
Source: stackoverflow.com
Related Query
- Datalabels plugin throws error when using scriptable option
- Chartjs: Overlapping values when using Datalabels plugin
- Chartjs Plugin Deferred throws "Uncaught TypeError: Cannot read property 'plugins' of undefined" error
- "Maximum call stack size" Error When Adding Data to Chartjs Using Props With Fetch (Vue/Chartjs)
- Chart.js returns a console error and does not display the chart when using variables as data input
- 'require is not defined' error when attempting to use chartjs in javascript code
- Error Message when using ChartJS with React
- How to run Chart.js samples using source code
- Moving vertical line when hovering over the chart using chart.js
- Chart.js: evenly distribute ticks when using maxTicksLimit
- angular 5 chart.js datalabels plugin
- TypeError: Cannot read property 'defaults' of undefined when using the react wrapper of chartjs
- How to properly use the chartjs datalabels plugin
- using chart-dataset-override option in angular-chart.js
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- Uncaught TypeError: Chart is not a constructor when using Chart.js
- Datalabels plugin chartjs showing '[object]' instead of value
- $(...).getContext("2d") is not a function when using chart.js
- Can't apply options of datalabels chartjs plugin in Vue
- Bars on chartjs superimpose when using type: 'time'
- using library without 'require' when using CDN
- Chart.js changes selected legend filters when using update function
- chartjs plugin datalabels does not show value on charts
- Implementing a choropleth chart using chartjs-chart-geo plugin with react-chartjs-2
- Chart JS chart not rendering in ArcGIS popup when using navigation arrows
- JavaScript critical error...Syntax Error (MVC 5) when passing array to Charts.js
- Maximum call stack error when attempting to update Chart in Vue js
- chartjs undefined length when using 2 datasets
- ChartJS does not display when using local Chart.js file
- How to generate color code dynamically by swapping 2 characters within a string using PHP
More Query from same tag
- Re-compile JSON data to make less rows
- Why chart renders after second click - react-chartjs-2
- Problem creating chart out of GET request with Angular
- Update Chart vue3-chart with new data
- Chart.js: Truncate Legend's Labels
- onAnimationComplete is executed before animation is done
- Remove radar chart labels in chart.js
- Chartjs (Non Vue) Not Rendering Graph Chart inside V-if/V-show
- Vuejs, how to build an object?
- Vue-Chartjs onComplete custom labels - prevent blinking
- Javascript highcharts code similar to image
- Chart.js using json data from MySQL
- Chartjs does not show on pdf in yii2 despite showing in html view
- after div display set to block nothing shows
- Implementing range slider in Chart.js
- Periodically refresh placeholder and canvas tag in Django template
- Filter dates from the first day of the month to the current date
- Chart js - Line chart cuts border for lines in boundaries
- Vue-Chartjs reactive chart options passing
- Chartjs React Typescript moving x axis labels above chart
- Datalabels plugin chartjs showing '[object]' instead of value
- I would like to show a line bar in chart.js with data automatically fetched from mockapi
- Why does one chart overlays another (chart.js)?
- How to decrease border width in any charts?
- How to access custom property in dataset object in Bar Chart in React ChartJS 2?
- Angular and ChartJS colors
- How should data be structured for lineplots with vue/chart.js
- Angular-chartjs expression/value inside canvas class
- Char.js Interpolation linear
- ChartJS - Issues with positioning and viewing various components of horizontal bar