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

neppoz's avatar

ChartJS API call

Hi all,

i am currently using consoletv/charts package for implmenting a chart. I want to update the Chart with an API request, but i can not resolve my issue. I am doing something essentially wrong maybe.

My Controller

public function stats() { $data = Regulartable::whereNotNull('eval_complete') ->orderBy('eval_complete', 'asc') ->pluck('stat_value', 'eval_complete');

    $chart = new RegulartableLineChart;
    $api = url('/getStatsData');

    $chart->labels($data->keys())->load($api);

    return view('stats', compact('products', 'chart'));
}

public function getStatsData(Request $request) { $data = Regulartable::whereNotNull('eval_complete') ->orderBy('eval_complete', 'asc')->pluck('stat_value', 'eval_complete');

    $chart = new RegulartableLineChart;

    $chart->dataset('New line Chart', 'line', $data->values());

    return $chart->api();
}

This is my output from the JSON request i get back.

[{"borderWidth":2,"data":[40,30,20,80,80,80,80,80,80,80,80,80,80,80,81,80,78.1,72.1,81.4,81.4,77.5,100,76.8,76.8,54.8,69.6,76.8,100,76.8,76.8,51.5,76.8,51.5,76.8,100,54.8,51.5,47.4,76.8,76.8,100,100,100,100,29.3,100,100,100,100,54.8,100,51.5,100,76.8],"label":"New line Chartxx","type":"line"}]

Maybe someone of you already did this, your help is appreciated. Thank you very much in advance.

0 likes
0 replies

Please or to participate in this conversation.