how to divide total score by score in javascript ?
I have a code to display the total score of each criterion, and I want to display it in percentage form on a graph.
I have totalscore in criteria:
and the expected output should be displayed as a percentage to be
My Controller:
public function getChartSecurity()
{
$result = DB::table('tbl_score_details')->select(DB::raw('sum(score) as totalscoreall'))->first();
$result = DB::table('tbl_score_details')
->join('tbl_criterias','tbl_criterias.id_criteria','tbl_score_details.criteria_id')
->select('tbl_criterias.criteria_name', DB::raw("Sum(score) as totalscore "), DB::raw('sum(score) as totalscoreall'))
->groupBy('criteria_name')
->orderBy('totalscore', 'DESC')
->get();
return response()->json($result);
}
I'm trying to make two queries with the same variable, the first is to retrieve the total score and the second query is to retrieve the total score for each criterion. But this didn't work. TotalScoreAll is undefined in javascript
My Javascript:
var url = "{{ url('pengawas/chart_security') }}"
var Criteria = new Array();
var TotalScore = new Array();
var TotalScoreAll = new Array();
$(document).ready(function(){
$.get(url, function(response){
response.forEach(function(data){
Criteria.push(data.criteria_name);
TotalScore.push(data.totalscore);
console.log(data.totalscoreall);
});
});
});
Please help me, thank you