leandrocfe / filament-apex-charts

Apex Charts integration for Filament PHP.
https://filament-apex-charts-demo.leandroferreira.dev.br
MIT License
286 stars 36 forks source link

Chart id is not unique when rendering component in a loop. #57

Closed maltebaer closed 6 months ago

maltebaer commented 6 months ago

If I try to render a Chart Widget in a loop, all of the charts get appended to the first component.

I guess it is due to protected static string $chartId = 'apexChart' being assigned a default value. Hence

/**
* Retrieves the chart id.
*
* @return string|null The chart id.
*/
protected function getChartId(): ?string
{
    return static::$chartId ?? 'apexChart_'.Str::random(10);
}

will never append a random string.

Changing the property to protected static ?string $chartId will do the trick but I'm not sure if this leads to unwanted side effects.

image

If you think making the property nullable will do the trick, I'm happy to submit a PR.

leandrocfe commented 6 months ago

@maltebaer thank you! Check the new version 3.1.1 https://github.com/leandrocfe/filament-apex-charts/releases/tag/3.1.1

maltebaer commented 6 months ago

Awesome, it works like charm! Thanks a lot for the quick fix!