Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel,Lavacharts,使用for循环显示多个图表_Php_Laravel - Fatal编程技术网

Php Laravel,Lavacharts,使用for循环显示多个图表

Php Laravel,Lavacharts,使用for循环显示多个图表,php,laravel,Php,Laravel,我正在尝试使用Lavacharts在laravel中使用for循环显示多个图表。我不知道是什么问题,但只显示最后一张图表。但最后一张图表显示正确 (我的控制器在一个图表中为每个图表生成两条线。一条是标准值,另一条是实际值。所有这些值在这些循环之前被初始化,并且它们正常工作。) 这是控制器: $i=0; foreach ($user_farms as $user_farm){ $user_farm_id = $user_farm->id; $user_flocks = \App\Flo

我正在尝试使用Lavacharts在laravel中使用for循环显示多个图表。我不知道是什么问题,但只显示最后一张图表。但最后一张图表显示正确

(我的控制器在一个图表中为每个图表生成两条线。一条是标准值,另一条是实际值。所有这些值在这些循环之前被初始化,并且它们正常工作。) 这是控制器:

$i=0;

foreach ($user_farms as $user_farm){


$user_farm_id = $user_farm->id;
$user_flocks = \App\Flock::where('farm_id', '=', $user_farm_id)->get();
$no_flocks = \App\Flock::where('farm_id', '=', $user_farm_id)->get()->count();

$j=0;

foreach ($user_flocks as $user_flock){

    $user_flock_id = $user_flock->id;
    $weights = \App\Weight::where('flock_id', '=', $user_flock_id)->orderBy('week_id', 'asc')->get();

    $weights_first = $weights ->first();
    $start_week = $weights_first->week_id;

    foreach($weights as $weight ){

        $age = $weight->week_id - $start_week ;
        $actual[$age] = $weight->female;

    }   


    $graph = Lava::DataTable();
    $graph->addStringColumn('Weeks')
         ->addNumberColumn('Standard')
         ->addNumberColumn('Actual')
         ->addRow(['1',  $standard[1], ($actual[1]>0? $actual[1] : null) ])
         ->addRow(['2',  $standard[2], $actual[2]])
         ->addRow(['3',  $standard[3], $actual[3]])
         ->addRow(['4',  $standard[4], $actual[4]])
         ->addRow(['5',  $standard[5], $actual[5]])
         ->addRow(['6',  $standard[6], $actual[6]])
         ->addRow(['7',  $standard[7], $actual[7]])
         ->addRow(['8',  $standard[8], $actual[8]])
         ->addRow(['9',  $standard[9], $actual[9]])
         ->addRow(['10',  $standard[10], $actual[10]]);


        Lava::LineChart($i.'graph'.$j, $graph, [
            'title' => 'Weights of '. $user_flock->name
        ]);
    $j++;
}

$i++;
}
这是视图,我正在使用刀片模板:

@for ($i = 0; $i < $no_farms; $i++)
    @for ($j = 0; $j < $no_flocks; $j++)


        <div id="graph_div"></div>
        @linechart($i.'graph'.$j, 'graph_div')


    @endfor    
@endfor
($i=0;$i<$no\u农场;$i++)的
@for
@对于($j=0;$j<$no_羊群;$j++)
@线形图($i.‘图形’。$j.‘图形分区’)
@结束
@结束

您正在为的
的每个过程中用id“graph\u div”覆盖相同的div。
因此,您应该为需要的每个图形更改div的id(“例如,graph_div_$i_$j”)


@折线图($i.“图形”$j,“图形分区”$i.“$j)

您可以使用
$lava->renderAll()在视图中,如所述
    <div id="graph_div_{{$i}}_{{$j}}"></div>
    @linechart($i.'graph'.$j, 'graph_div_'.$i.'_'.$j)