Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noraBouhssis's avatar

Invalid data table format: must have at least 2 columns.

Good evening!

I'm working with Laravel 5.4 and consoletvs charts version 4. I want to make a multiline chart that contains data from two diffrent tables . i want to show the number of records of each table grouped by day. i tried this but it gives me error:

ChartController.php:

 public function chart()
{

$dechet = DB::table('dechets')

    ->select(DB::raw('EXTRACT(DAY FROM heure) as day'),DB::raw('count(*) as dechets'))

    ->groupBy('day')

    ->get()->toArray();    

$dechet = json_encode($dechet);

$incident = DB::table('incidents')

    ->select(DB::raw('EXTRACT(DAY FROM heure) as day'),DB::raw('count(*) as incidents'))

    ->groupBy('day')

    ->get()->toArray();

$incident = json_encode($incident); 

$chart = Charts::multiDatabase('line', 'material')
            ->responsive(true)
            ->dimensions(780, 500)
            ->template("material")
            ->colors(['#ff0000', '#00ff00'])
            ->dataset('Dechets', $dechet)
            ->dataset('Incidents', $incident)
            ->labels(['1', '2', '3', '4', '5', '6', '7', '8','9', '10', '11', '12','13', '14', '15', '16','17', '18', '19', '20','21',
            '22', '23', '24','25', '26', '27', '28','29', '30']);

 return view('admin.home')->withchart($chart);
 }

home.blade.php:

  <div style="width: 75%;">
         {!! $chart->render() !!}
  </div>

please help me.

Thank you.

0 likes
0 replies

Please or to participate in this conversation.