如何在laravel项目的图表JS中设置日期选择器

时间:2019-05-09 06:24:23

标签: javascript php laravel charts

我想在图表顶部设置日期选择器以选择日期范围,但我不知道该怎么做

现在我有一个图表,可以显示一个月中每天的帖子数量,并且我希望有一个范围日期来显示该范围的帖子

这是我的控制器

public function home()
{
    $articles = Article::select('id', 'created_at')
        ->get()
        ->groupBy(function($date) {
            return Carbon::parse($date->created_at)->format('m'); // grouping by months
        });
    $chartOptions = [
        'scales' => [
            'yAxes' => [
                [
                    'ticks' => [
                        'beginAtZero' => true,
                    ],
                ],
            ],
        ],
    ];
    $chartjs = app()->chartjs
        ->name('lineChartTest')
        ->type('bar')
        ->size(['width' => 400, 'height' => 200])
        ->labels(['Feb','Mar','Apr','May','June','July','Aug','Sept','Sept','Nov'])
        ->datasets([
            [
                "label" => "My Second dataset",
                'backgroundColor' => "rgba(138, 22, 54, 0.31)",
                'borderColor' => "rgba(138, 125, 154, 0.7)",
                "pointBorderColor" => "rgba(38, 285, 14, 0.7)",
                "pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
                "pointHoverBackgroundColor" => "#fff",
                "pointHoverBorderColor" => "rgba(120,20,220,1)",
                'data' => [$articles['02']->count(), $articles['03']->count(), $articles['04']->count(), $articles['05']->count(), $articles['06']->count(), $articles['07']->count(), $articles['08']->count(), $articles['09']->count(), $articles['10']->count(), $articles['11']->count()],
                "borderWidth" => 3,
                "beginAtZero" => true
            ]

        ])->options($chartOptions);



    return view('app.index', compact('chartjs','articles'));



}

0 个答案:

没有答案