I have this controller:
public function main()
{
$user=User::find(1);
return view('home')->with('user',$user);
}
And in the home.blade.php view, i need to get the user's attributes travel, food, misc. I can get those using $user->travel, $user->food, $user->misc which are integers.
but, i have to show these expenses in pie chart. So, i use chart.js
Travel Expenses:{{$user->travel}}<br>
Food Expenses:{{$user->food}}<br>
Miscellaneous Expenses:{{$user->misc}}<br>
<canvas id="myChart"></canvas>
<script>
var ctx = document.getElementById("myChart");
var data = {
labels: [
"Travel",
"Food",
"Miscellaneous"
],
datasets: [
{
data: [300, 50, 100],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
};
</script>
This will show static data 300,50, and 100. How can i add these data dynamically? I need data: [300, 50, 100], to be something like data: [$user->travel, $user->food, $user->misc],