ArielMejiaDev / larapex-charts

A Laravel wrapper for apex charts
https://larapex-charts.netlify.app/
MIT License
284 stars 84 forks source link

added .setExtraOptions #74

Closed sfinktah closed 7 months ago

sfinktah commented 1 year ago

To get serious use out of the apexcharts library, it was necessary to expose the complete range of options.

It is now possible to create much more capable graphs, by passing an apexcharts style options argument to setExtraOptions(), e.g.:

        $options = [
            'chart' => [
                'stacked' => true,
            ],
            'fill' => [
                'opacity' => 0.5,
            ],
            'tooltip' => [
                'fixed' => [
                    'enabled' => true,
                    'position' => 'topRight',
                ],
                'followCursor' => true,
            ],
            'plotOptions' => [
                'bar' => [
                    'borderRadius' => 0,
                    'stroke' => [
                        'width' => 5,
                    ],
                ],
                'line' => [
                    'stroke' => [
                        'width' => 8,
                    ]
                ],

            ],
        ];

        return $this->withMeta([
            'chart' => $this->chart->lineChart()
                ->setTitle('Scraping Delay')
                ->addData('minutes', $result->pluck('minutes')->map(fn ($v) => round($v))->all(), 'line')
                ->addData('impressions', $result->pluck('latest_impressions')->all(), 'column')
                ->addData('articles', $result->pluck('latest_articles')->all(), 'column')
                ->addData('failed', $result->map(fn ($row) => $row->failed < $row->minutes ? $row->failed : 0)->map(fn ($v) => round($v))->all(), 'area')
                ->setLabels($result->pluck('name')->all())
                ->setStroke(['curve' => 'stepline'])
                ->setFontColor('currentColor')
                ->setSparkline()
                ->setWidth(512)
                ->setHeight(212)
                ->setExtraOptions($options)
                ->toVue(),
        ]);
ArielMejiaDev commented 7 months ago

@sfinktah thanks for the PR as it could lead to some breaking changes I need to take some time to figure out how this could make sense at this moment you are able to override options with a new trait introduced by #33

At this moment I would decline this PR, but the idea of override options by a chaining method makes a lot of sense