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 chart is not rendered correctly when fetching data from DB for the 'data' array #61

Open
kylescousin opened this issue May 1, 2022 · 0 comments

Comments

@kylescousin
Copy link

I have this table which logs a daily record for the amount of holders for a certain crypto. It's simply "DAY" => "HOLDERS" - and I want to plot this out in a chart. The problem is that there seems to be an issue with the chart rendering before the data is being pulled from the database.

When logging the $holders that are taken from the database and $holders that is hardcoded, it shows the exact same array. Yet, when providing it to the 'data' field in the Linechart, it only works when providing the hardcoded declared array. Why is this, and how can this be fixed?

        $holders = \App\Models\Holder::where('crypto_id', $request->get('viaResourceId'))
            ->select('day', 'active_addresses')
            ->get();

        //Fetching the values from DB doesn't render the chart correctly.
        $days = $holders->pluck('day')->toArray();
        $holders = $holders->pluck('active_addresses')->toArray();

        //Hardcoding the values renders the chart correctly.
        $daysStatic = [1,2,3];
        $holdersStatic = [963625,963625,96325];

        app('debugbar')->info($holders);
        app('debugbar')->info($holdersStatic);
  (new LineChart())
                ->title('Holders')
                ->series(array([

                    'label' => 'Holders by day',
                    'borderColor' => '#f7a35c',
                    'data' => $holdersStatic
                ]))
                ->options([
                    'xaxis' => [
                        'categories' => $daysStatic // <== If you put $days here instead of $daysStatic - it doesn't render the chart.
                    ],
                ])
                ->onlyOnDetail()->width('2/3'),
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

1 participant