Skip to content

Error from example from README: #32

@samtuke

Description

@samtuke

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 chart

Expected behavior
A chart is printed

Actual behavior
Just the error message above

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions