Ok I will send you a the original code maybe in an hour or more, but at this moment I think you should review in header of your template, you need to have :
i've played around with the code and the chart is rendered.
now i'm trying to pass data from my project's controller via two query's
one for the labels and one for the data - those two results i have stored in two variables in the controller. i then attempted to insert those variables into the relevant field functions: labels, dataset..
but what i get is an empty table with "object Object" in the x axis and 0 - 1.0 in the y axis but no line is rendered.
i've tried to die-dump the variables. then i figured out i can parse them "toArray()" but still i got the same result.
The code is already added in the post, ok Maybe because the "toArray()" function returns a wrapper that certanly is similar to array you can access to data like an array, but It is not a pure php array because you can use some methods with the result array, maybe try adding mock data "[10,40,20]" and pass it at "dataset()" method.
$usersChart->dataset('all users named like john of age 44 and up', 'line', $data)
->color("rgb(255, 99, 132)")
->backgroundcolor("rgb(255, 99, 132)")
->fill(true)
->linetension(0.3);
I recommend you to make first a dd() of $label, maybe it returns an array of Users model collection and you need to pass a simple array not a multidimensional one, so maybe you need something like:
Sorry im new to this community and am trying to see how i can send code snippets like tou do.
Ive dye dumped the label and dataset collections (the come from querries) and i recieve a collection of php arrays. The problem is that they are key value paired so im guessing the blade does get an object and not an array of data.
Ive looked around for different methids and it seems there might be a get_data() function that takes the params and returns an array.
If it works ill let you know.
If you have some insights for me i'll be more than happy.
Thanks I try to explain it as much as I can, you write markdown in dev.to, so to write code snippets you only need to add alt+96 it writes " ` " you need to write this aphostrophe three times to open a block and three times to close the block, inside the block just paste your code, I think that you can use other ways to get data as you want but is a eloquent stuff, if you wish you can paste the dd() output and maybe I could help.
Happy code!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ok I will send you a the original code maybe in an hour or more, but at this moment I think you should review in header of your template, you need to have :
If you already have it, remember to end your template with:
I will send you an example, thanks for follow the post.
so,
i've played around with the code and the chart is rendered.
now i'm trying to pass data from my project's controller via two query's
one for the labels and one for the data - those two results i have stored in two variables in the controller. i then attempted to insert those variables into the relevant field functions: labels, dataset..
but what i get is an empty table with "object Object" in the x axis and 0 - 1.0 in the y axis but no line is rendered.
i've tried to die-dump the variables. then i figured out i can parse them "toArray()" but still i got the same result.
any idea's what i should do ?
The code is already added in the post, ok Maybe because the "toArray()" function returns a wrapper that certanly is similar to array you can access to data like an array, but It is not a pure php array because you can use some methods with the result array, maybe try adding mock data "[10,40,20]" and pass it at "dataset()" method.
so...the mock data works just fine.
but i want to pass data from something like this:
$label = DB::table('users')->where('name', 'like', '%john%')->get('name');
and then pass the variable $label to the chart like so:
$usersChart->labels($label);
the same for the dataset:
$data = DB::table('users')->where('name', 'like', '%john%')->get('age');
$usersChart->dataset('all users named like john of age 44 and up', 'line', $data)
->color("rgb(255, 99, 132)")
->backgroundcolor("rgb(255, 99, 132)")
->fill(true)
->linetension(0.3);
but when i dye dump it says they are collections holding arrays. and the chart does not work :/
I recommend you to make first a dd() of $label, maybe it returns an array of Users model collection and you need to pass a simple array not a multidimensional one, so maybe you need something like:
you need to see something like:
I mean maybe you try this but just to be sure if these not work, you can create a array from a loop, it is not elegant way but only to be sure:
Later you can use a tap() method to make it more elegant
Hi ariel,
Sorry im new to this community and am trying to see how i can send code snippets like tou do.
Ive dye dumped the label and dataset collections (the come from querries) and i recieve a collection of php arrays. The problem is that they are key value paired so im guessing the blade does get an object and not an array of data.
Ive looked around for different methids and it seems there might be a get_data() function that takes the params and returns an array.
If it works ill let you know.
If you have some insights for me i'll be more than happy.
Other than that thank you so much !
Thanks I try to explain it as much as I can, you write markdown in dev.to, so to write code snippets you only need to add alt+96 it writes " ` " you need to write this aphostrophe three times to open a block and three times to close the block, inside the block just paste your code, I think that you can use other ways to get data as you want but is a eloquent stuff, if you wish you can paste the dd() output and maybe I could help.
Happy code!