Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda