I want to pass variable indexes from laravel controller to view on the javascript area so i can create chart
My Controller
<?php
namespace App\Http\Controllers;
use App\GenderSeries;
use Illuminate\Http\Request;
class EventDashboardController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$titles = GenderSeries::select('titles','numbers')->get();
return view('events.dashboard',compact('titles'));
}
}
and my view file
@extends('layouts.templates.event')
@section('title','Store Dashboard')
@section('content')
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<canvas id="genderCount" width="100%" height="80"></canvas>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<canvas id="genderTitle" width="100%" height="80"></canvas>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
//Show graph of individuals count by gender
var ctx = document.getElementById('genderTitle');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: {!! $titles !!},
datasets: [{
label: '# Gender Series',
data:{!! $titles !!},
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}]
},
}
});
</script>
@endsection
On the javascript labels, I want to display titles on the javascript dataset data I want to display the numbers to make a chart.
when I tried that I got this and view my source code
<script>
//Show graph of individuals count by gender
var ctx = document.getElementById('genderCount');
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: [{"title":"Feminism","numbers":"50"}],
datasets: [{
label: '# Individual By Gender',
data:[{"title":"Feminism","numbers":"50"}],
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}]
},
}
});
</script>
I need help to fix this