如何将许多元素传递给Morris。

时间:2019-07-04 05:04:35

标签: javascript php ajax laravel

我在laravel中拥有下一个控制器,该控制器返回一个人的ID和与该人相关的特定数字。

public function obtenerDatoss(){
    $dato = DB::table('evidencias')
                            ->join('profesor','evidencias.user_id','=','profesor.user_id')
                            ->select(DB::raw('run, count(*) as num_ev'))
                            ->groupBy('evidencias.user_id','run')
                            ->get();

    return json_encode($dato);

}

这是控制器的结果

[{"run":"11123112-3","num_ev":"1"},{"run":"19696122-4","num_ev":"19"},{"run":"123123123","num_ev":"1"}]

这是我的一部分观点

<div class="col-md-12">
        <button class="btn btn-block btn-success btn-flat" type="button" id="consultar">
          Consultar
        </button>
      </div>
    </div>
<div class="box box-danger">
          <div class="box-header with-border">
            <h3 class="box-title">Solicitudes enviadas por profesor</h3>

            <div class="box-tools pull-right">
              <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
              </button>
              <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
            </div>
          </div>
          <div class="box-body chart-responsive">
            <div class="chart" id="chart1" style="height: 300px; position: relative;"></div>
          </div>
</div>

然后是脚本

<script>

$(function () {
"use strict";
$("#consultar").on("click",function(){
    var url = "obtenerDatos2";
    $.get(url,function(resul){
        var datos= jQuery.parseJSON(resul);
        var num_ev = datos[0].num_ev;
        var runprof = datos[0].run;

        //CHART 1
        var chart1 = new Morris.Donut({
          element: 'chart1',
          resize: true,
          colors: ["#3c8dbc", "#f56954", "#00a65a", "#430e45"],
          data: [
            {label: runprof, value: num_ev},
            {label: runprof, value: num_ev}
          ],
          hideHover: 'auto'
        });
    })

});


</script>

如果我在脚本中执行此操作,则可以,但是我需要获取所有元素,并且我不知道如何使用for循环或类似方法执行此操作,

0 个答案:

没有答案