F
Filament2y ago
Noor

charts

I'm building mixed chart type widget, One chart is line and the other is Bar both of them have data from different tables.. so how can I retrieve there data from each table ... and I'm not using apex chart so if there is any other solution please tell me........ I'm already using getFilter and trenvalue map function but it only retrieve data of one graph ty
15 Replies
awcodes
awcodes2y ago
Is the problem only happening when you filter? If it’s only querying one table then I’d recommend just doing two separate queries with Trend::query. Then just map each one separately into different data objects.
Noor
NoorOP2y ago
Can you please show me an example because If I use two trend queries with the same filter attribute twice, it doesn't work @awcodes
awcodes
awcodes2y ago
can you provide your widget code?
Noor
NoorOP2y ago
Noor
NoorOP2y ago
Noor
NoorOP2y ago
Noor
NoorOP2y ago
@awcodes
awcodes
awcodes2y ago
$submissionData = Trend::model(Submission::class)....
$leadData = Trend::model(Lead::class)....

'datasets' => [
[
'label' => 'Submissions',
'data' => $submissionData->map(fn (TrendValue $value) => $value->aggregate),
],
[
'label' => 'Leads',
'data' => $leadData->map(fn (TrendValue $value) => $value->aggregate),
],
],
$submissionData = Trend::model(Submission::class)....
$leadData = Trend::model(Lead::class)....

'datasets' => [
[
'label' => 'Submissions',
'data' => $submissionData->map(fn (TrendValue $value) => $value->aggregate),
],
[
'label' => 'Leads',
'data' => $leadData->map(fn (TrendValue $value) => $value->aggregate),
],
],
This is what i meant
Noor
NoorOP2y ago
and labels like this ? 'labels' => $submissionData->map(fn (TrendValue $value) => $value->date), 'labels' => $leadData->map(fn (TrendValue $value) => $value->date), @awcodes
awcodes
awcodes2y ago
you can only have one set of labels
Noor
NoorOP2y ago
then it shows data error
awcodes
awcodes2y ago
but since both would have the same dates you could use either one for the lables
Noor
NoorOP2y ago
undefined variable $data
awcodes
awcodes2y ago
'datasets' => [
[
'label' => 'Submissions',
'data' => $submissionData->map(fn (TrendValue $value) => $value->aggregate),
],
[
'label' => 'Leads',
'data' => $leadData->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $leadData->map(fn (TrendValue $value) => $value->date)
'datasets' => [
[
'label' => 'Submissions',
'data' => $submissionData->map(fn (TrendValue $value) => $value->aggregate),
],
[
'label' => 'Leads',
'data' => $leadData->map(fn (TrendValue $value) => $value->aggregate),
],
],
'labels' => $leadData->map(fn (TrendValue $value) => $value->date)
in my head that should work
Noor
NoorOP2y ago
okay I'll try that thankyou so much @awcodes

Did you find this page helpful?