Accessing query results within a Nova card
I'm trying to use this Nova ChartJS package to show the results of a lens: https://coroo.github.io/nova-chartjs
However, it seems to only allow adding a model reference or statically adding the values according to the examples in the docs, which is completely useless in with generated data.
Example from the docs:
public function cards(NovaRequest $request)
{
return [
(new StackedChart())
->title('Revenue')
->series([
[
'barPercentage' => 0.5,
'label' => 'Product #1',
'backgroundColor' => '#ffcc5c',
'data' => [30, 70, 80],
],
])
->options([
'xaxis' => [
'categories' => ['Jan', 'Feb', 'Mar'],
],
]),
];
}
It would be fine if I could iterate thru a collection of the results of the lens to generate the data for the series, but I can't seem to figure out how to access the underlying data shown by the lens within the card method.
How it would actually be useful so I can work with the actual data in the chart:
public function cards(NovaRequest $request)
{
return [
(new StackedChart())
->title('Revenue')
->series($this->results->map(function ($record) {
return [
'barPercentage' => $record->percentage,
'label' => $record->name,
'backgroundColor' => $record->color,
'data' => $record->data,
] ;}))
->options([
'xaxis' => [
'categories' => $this->results->map(function ($record) {
return $record->created_at->day;
}),
],
]),
];
}
How can I get access to the actual resource data for use in a card?
Please or to participate in this conversation.