Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
how to divide total score by score in javascript

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:

  1. Criteria 1 : totalscore = 3
  2. Criteria 2 : totalscore = 2

and the expected output should be displayed as a percentage to be

  1. Criteria 1: percent = (3/5)*100 = 60%
  2. Criteria 2: percent = (2/7)*100 = 40%

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);
      });

  });
});

Result when i tried enter image description here

Please help me, thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!