Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The right syntax to add options #102

Open
romain-lgr opened this issue Mar 8, 2024 · 4 comments
Open

The right syntax to add options #102

romain-lgr opened this issue Mar 8, 2024 · 4 comments

Comments

@romain-lgr
Copy link

Hello!,

I am a bit struggling with the options features. I am trying to add options to my area chart like this but I can not make it work. Is it the good way to add options?

$salesData = $this->calculateSalesData();
        $totalSales = array_sum($salesData['sales']);

        $options = [
            'yaxis' => [
                'labels' => [
                    'formatter' => function ($value) {
                        return Money::JPY($value);
                    },
                ],
            ],
        ];

        return $this->chart->areaChart()
            ->setTitle('Ticket Sales - ' . Money::JPY($totalSales))
            ->setHeight(350)
            ->addData('Sales', $salesData['sales'])
            ->setXAxis($salesData['days'])
            ->setColors(['#cddaea'])
            ->setOptions($options)
            ->toVue();

Thank you

@marineusde
Copy link
Contributor

In the documentation of apexcharts "formatter" is a js callback function:

https://apexcharts.com/docs/options/yaxis/

It worked this example:

        $options = [
            'yaxis' => [
                'labels' => [
                    'formatter: function(val, index) {
                        return val.toFixed(2);
                    }'
                ],
            ],
        ];

In my own code I

@lukejames1111
Copy link

I too am struggling with the ->setOptions($options) feature. I'm trying to do something similar:

$options = [
    'yaxis' => [
        'decimalsInFloat' => 0,
    ]
];
$chart = (new OriginalLineChart)
    ->addData('Total Viewings', $weeklyViewings)
    ->addData('Trend Line', $trendLine)
    ->setXAxis($labels)
    ->setGrid()
    ->setStroke(2, [], 'smooth')
    ->setHeight(300)
    ->setOptions($options)
;

But every time I try to do that I get Call to undefined method ArielMejiaDev\LarapexCharts\Charts\LineChart::setOptions()

@smitmartijn
Copy link

If you're seeing Call to undefined method - maybe you've got an older version installed. But, the setOptions doesn't seem to do anything, except set options within the class - but then those options aren't called on when rendering the chart.

@pandigresik made this commit: 480d8f7 to add options override support, but that didn't change the rendering of the script in https://github.com/ArielMejiaDev/larapex-charts/blob/master/stubs/resources/views/chart/script.blade.php

I'm going to try and make setOptions effective, then submit a PR.

@lukejames1111
Copy link

I saw the commit, but I only installed this a couple of weeks ago. The only way that I could figure out how to change the options was to edit them directly unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants