Highcharts

In this section we will reproduce the same chart as the Your First Chart section of the Highcharts docs.

After installing Axis and Highcharts, we can instantiate a chart object and pass it to a view on a controller:

use Axis\Chart;

class ExampleController extends Controller
{
    public function __invoke(): View
    {
        $chart = Chart::highcharts()
            ->bar()
            ->title('Fruit Consumption')
            ->labels(['Apples', 'Bananas', 'Oranges'])
            ->series('Jane', [1, 0, 4])
            ->series('John', [5, 7, 3])
            ->options(['yAxis' => ['title' => ['text' => 'Fruit eaten']]]);

        return view('example.chart', compact('chart'));
    }
}

On the blade file:

<section>
    <div>{{ $chart }}</div>
</section>

You should get a chart like this:

Pretty simple, right?

Last updated on