Types appear to be wrong for scriptable options
See original GitHub issueExpected Behavior
I am using a function as the value of backgroundColor
on a bar chart. The allowed types should include a function that returns a color.
Current Behavior
The allowed types do not include a funciton:
Type '(context: any, options: any) => string' is not assignable to type 'string | _DeepPartialObject<CanvasGradient> | _DeepPartialObject<CanvasPattern> | undefined'.
Steps to Reproduce
import { ChartConfiguration } from 'chart.js';
const getConfig = (): ChartConfiguration<'bar'> => {
return {
type: 'bar',
options: {
backgroundColor: context => {
return '#fff'
},
}
}
}
Environment
- Chart.js version: 3.5.0
- Typescript: 4.3.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Incorrect context for plugin options when scriptable #8623
When you are accessing to a plugin (i.e. datalabels) option which has been defined as a callback, by chart.options , for instance clicking...
Read more >Chart.js how to use scriptable options - Stack Overflow
I am trying to set the xAxis zeroLineColor to "#FFFFFF" and I want to have the Grid line color as "#00FFFF" but as...
Read more >ScriptableObject behaviour discussion (how Scriptable ...
When creating a ScriptableObject at runtime, it does not appear in the Project's Assets folder, nor does it appear in the Hierarchy.
Read more >Dynamic point size, labels, & more with Chart.js scriptable ...
I've gotten a couple questions recently about how to dynamically set the size of points for on Chart.js line chart.
Read more >TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mb it indeed is configurable there, in that case it’s indeed an issue with the typing
I am just using
options.datasets.bar.backgroundColor
instead so I guess this is a bug report rather than a request for help but thank you.It seems to me that either the types are wrong or the implementation is wrong as it does work i.e. you can set the background color using a
backgroundColor
function in the options namespace.I think the docs are a bit confusing if you are not meant to do that. I interpreted the page here (https://www.chartjs.org/docs/latest/charts/bar.html) as saying any of those options were available in any of the listed namespaces.