I'd like to implement line segment styling in a TYPO3 dashboard widget.
My data provider implements TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface and provides a getChartData() method which returns the data in the format expected by Chart.js, so if I want every segment to be dashed this works:
public function getChartData(): array
{
return [
'labels' => [...],
'datasets' => [
[
'label' => ...,
'data' => [...],
'segment' => [
'borderDash' => [6, 6]
]
], ...
]
];
}
I'd like to have the borderDash calculated based on the context of the segment. What I'd like to do that doesn't work is something like:
public function getChartData(): array
{
return [
'labels' => [...],
'datasets' => [
[
'label' => ...,
'data' => [...],
'segment' => [
'borderDash' => 'ctx => ctx.p0.parsed.y == 0 ? [6,6] : undefined'
]
], ...
]
];
}
How can I return executable Javascript from getChartData()? (Or, is there a better way to solve this problem?)