Open zodwick opened 11 months ago
Another work around we have is It's not much different. Just another option of the same thing.
const options = {
// ... (other options)
plugins: {
tooltip: {
// ... (other tooltip options)
},
legend: {
...
position: "bottom" as const,
align: "end" as const,
},
},
};
hi, how about this way,
import type { ChartOptions } from 'chart.js' const options: ChartOptions = { ... }
How about this?
const options: any = {
plugins: {
legend: {
position: "right",
},
},
};
Would you like to work on a fix?
Current and expected behavior
Issue Title: Unable to Assign 'position' Property in Chart.js Options
Issue Description:
When attempting to add the 'position' property as per the Chart.js documentation, it successfully produces the desired output. However, it results in a type error in the options object when passing it to the
Bar
component fromreact-chartjs-2
.Code:
Error Message:
Notes:
plugins.legend
object."bottom" | "center" | "left" | "top" | "right"
but is being assigned a string value.Expected Behavior:
The code should allow the 'position' property to be set in the
plugins.legend
object without type errors, in accordance with the Chart.js documentation.Reproduction
running the above code to create a sample react app in nextjs with ts reproduces the issue.
chart.js version
4.4.0
react-chartjs-2 version
5.2.0
Possible solution
this works . so I am guessing that instead of a string, "bottom","end" ..etc are defined as types of their own . correcting the type definitions will be enough (i think ) . I'd be happy to do the same with some guidance (kinda new to this ) thanks :)