-
Notifications
You must be signed in to change notification settings - Fork 6
Error from example from README: #32
Copy link
Copy link
Closed
Labels
Description
Describe the bug
After copy pasting verbatim the example from README, I get this error:
Warning: Undefined array key "datasets" in /Users/samtuke/www/foo/vendor/bbsnly/chartjs-php/src/Config/Config.php on line 22
Notice: Indirect modification of overloaded property Bbsnly\ChartJs\Config\Data::$datasets has no effect in /Users/samtuke/www/foo/public/customer-campaign.php on line 89
To Reproduce
Steps to reproduce the bug:
<?php
use Bbsnly\ChartJs\Chart;
use Bbsnly\ChartJs\Config\Data;
use Bbsnly\ChartJs\Config\Dataset;
use Bbsnly\ChartJs\Config\Options;
$chart = new Chart;
$chart->type = 'line';
$data = new Data();
$data->labels = ['Red', 'Green', 'Blue'];
$dataset = new Dataset();
$dataset->data = [5, 10, 20];
$data->datasets[] = $dataset->data;
$chart->data($data);
$options = new Options();
$options->responsive = true;
$chart->options($options);
$chart->get(); // Returns the array of chart data
$chart->toJson(); // Returns the JSON representation of the chart data
$chart->toHtml('my_chart'); // Returns the HTML and JavaScript code for the chartExpected behavior
A chart is printed
Actual behavior
Just the error message above
Reactions are currently unavailable