Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda