{{-- Question has graph? --}} @if (!empty($question->has_graph) && !is_null($question->graph)) @php $dataChart = json_decode($question->graph->data, true); $dataChart = is_array($dataChart) ? $dataChart : []; $chart_count = count($dataChart["datasets"]); $chart_type = $question->graph->type; @endphp @if($chart_type=="pie") @for($i=0;$i<$chart_count;$i++) @if($chart_count==1)
@else
@endif @endfor @else
@endif @push('chartJS') @if($chart_type!="pie") var config_{{$question->id}} = { type: '{{$question->graph->type}}', data: @json($dataChart), options: { responsive: true, legend: { position: 'bottom', }, hover: { mode: 'index' }, scales: { xAxes: [{ display: true, scaleLabel: { display: true, labelString: '' } }], yAxes: [{ display: true, scaleLabel: { display: true, labelString: 'Value' } }] }, title: { display: true, text: '{{$question->graph->title}}' } } }; var ctx_{{$question->id}} = document.getElementById('canvas_{{$question->id}}').getContext('2d'); new Chart(ctx_{{$question->id}}, config_{{$question->id}}); @else @for($i=0;$i<$chart_count;$i++) const data{{$i}} = { labels: ["{!! implode('","',$dataChart['labels']) !!}"], datasets: [ { data: ["{!! implode('","',$dataChart['datasets'][$i]['data']) !!}"], backgroundColor: ['#ff5050', '#ff9900', '#99cc00', '#33cc33', '#00cc99', '#0066ff', '#6666ff', '#cc33ff', '#cccc00', '#009933', '#cc3399'], } ] }; const config{{$i}}_{{$question->id}} = { type: 'pie', data: data{{$i}}, options: { responsive: true, plugins: { legend: { position: 'top', }, tooltip: { usePointStyle: false, } }, title: { display: true, text: '{!! $dataChart['datasets'][$i]['label'] !!}' } }, }; var ctx{{$i}}_{{$question->id}} = document.getElementById('canvas{{$i}}_{{$question->id}}').getContext('2d'); new Chart(ctx{{$i}}_{{$question->id}}, config{{$i}}_{{$question->id}}); @endfor @endif @endpush @endif