Как установить начальное значение как «0» в Chart.js Laravel - PullRequest
1 голос
/ 08 мая 2019

Я использую Chart.js в своем проекте Laravel, и я не знаю, как мне установить мой график на ноль.

$chartjs = app()->chartjs
    ->name('lineChartTest')
    ->type('bar')
    ->size(['width' => 400, 'height' => 200])
    ->labels(['02', '03', '04', '05', '06', '07', '08', '09', '10', '11'])
    ->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,
        ]

    ])
    ->options([]);

Ответы [ 2 ]

1 голос
/ 08 мая 2019

Вам нужно будет установить параметр beginAtZero:

$chartOptions = [
    'scales' => [
        'yAxes' => [
            [
                'ticks' => [
                    'beginAtZero' => true,
                ],
            ],
        ],
    ],
];

->options($chartOptions);
0 голосов
/ 08 мая 2019

Если вы хотите, чтобы ось Y начиналась с нуля, вы можете включить ее в опции

options: {
    scales: {
        yAxes: [{
            ticks: {
                beginAtZero: true
            }
        }]
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...