1👍
✅
Use the collection method pluck()
:
@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->pluck('title') !!},
datasets: [{
label: '# Gender Series',
data:{!! $titles->pluck('numbers') !!},
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
}
}]
},
}
});
</script>
@endsection
Source:stackexchange.com