php - Laravel, Lavacharts, displaying multiple charts using a for loop -


i trying display multiple charts using loop in laravel using lavacharts. dont know problem last chart displayed. last chart correctly displayed.

(my controller generates 2 lines in chart each chart. 1 standard value , actual value. values intialized before these loops , work correctly.) here controller:

$i=0;  foreach ($user_farms $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 $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 $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++; } 

and here view, using blade templating:

@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 

you overwriting same div id 'graph_div' in each pass of for. should change id of div each graph need ("graph_div_$i_$j", example.)

    <div id="graph_div_{{$i}}_{{$j}}"></div>     @linechart($i.'graph'.$j, 'graph_div_'.$i.'_'.$j) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -