0👍
Who are interested, I found solution. Here is the code:
<?php
namespace App\Http\Controllers;
use App\Content;
use App\Charts\UserLineChart;
use Illuminate\Http\Request;
class ChartController extends Controller
{
public function index(Request $request)
{
$content = Content::where('vei_sn', '23333')->get();
if ($request->has('date_from') && $request->input('date_from') != '' && $request->has('date_to') && $request->input('date_to') != '') {
$datefrom = $request->input('date_from');
$dateto = $request->input('date_to');
// $content = $content->where(function($query) use ($datefrom, $dateto){
// $query->whereBetween('op_date',array($datefrom, $dateto));
// });
$content = $content->whereBetween('op_date', [$datefrom, $dateto]);
}
$OBD = $content->where('con_type', 'OBD')->count();
$DC = $content->where('con_type', 'DC')->count();
$BSL = $content->where('con_type', 'BSL')->count();
$content = $content->pluck('con_type', 'con_type');
$chart = new UserLineChart;
$chart->labels($content->values());
$chart->dataset('Connections', 'bar', [$OBD, $DC, $BSL])->backgroundColor([
'red',
'green',
'yellow'
]);
return view('chart.index', compact('chart'));
}
}
- Chartjs-How to use chartjs-plugin-trendline with react-chartjs-2
- Chartjs-Colors are not updated when updating chart
Source:stackexchange.com