# Advance usage

Here add more complex examples with every chart that this package support:

WARNING

This package support many, (the most popular charts) of the apex chart library, but there are a few unsupported at the moment.

# Pie

The pie chart is the default one and is very easy to create.

$chart = (new LarapexChart)->setTitle('Posts')
        ->setDataset([150, 120])
        ->setLabels(['Published', 'No Published']);

# Donut

    $chart = (new LarapexChart)->setType('donut')
        ->setTitle('Posts')
        ->setDataset([150, 120])
        ->setColors(['#dc3545', '#ffc73c'])
        ->setLabels(['Published', 'No Published']);

# Radial

    $chart = (new LarapexChart)->setTitle('Products with more profit')
        ->setSubtitle('From January To March')
        ->setType('radialBar')
        ->setLabels(['Product One', 'Product Two', 'Product Three'])
        ->setXAxis(['Jan', 'Feb', 'Mar'])
        ->setDataset([60, 40, 79]);

# Line

Be carefull with setDataset() method

Some charts support in setDataset() a simple array (pie, donut, radialbar) as param, other charts only support multidimensional arrays (line, area, bar, horizontalbar, heatmap).

    $chart = (new LarapexChart)->setType('line')
        ->setTitle('Total Users Monthly')
        ->setSubtitle('From January to March')
        ->setXAxis([
            'Jan', 'Feb', 'Mar'
        ])
        ->setDataset([
            [
                'name'  =>  'Active Users',
                'data'  =>  [250, 700, 1200]
            ]
        ]);

# Area

    $chart = (new LarapexChart)->setType('area')
            ->setTitle('Total Users Monthly')
            ->setSubtitle('From January to March')
            ->setXAxis([
                'Jan', 'Feb', 'Mar'
            ])
            ->setDataset([
                [
                    'name'  =>  'Active Users',
                    'data'  =>  [250, 700, 1200]
                ]
            ]);

# Bar

        $chart = (new LarapexChart)->setTitle('Net Profit')
        ->setSubtitle('From January To March')
        ->setType('bar')
        ->setXAxis(['Jan', 'Feb', 'Mar'])
        ->setGrid(true)
        ->setDataset([
            [
                'name'  => 'Company A',
                'data'  =>  [500, 1000, 1900]
            ],
            [
                'name'  => 'Company B',
                'data'  => [300, 900, 1400]
            ],
            [
                'name'  => 'Company C',
                'data'  => [430, 245, 500]
            ]
        ])
        ->setStroke(1);

# Horizontal Bar

        $chart = (new LarapexChart)->setTitle('Net Profit')
        ->setSubtitle('From January To March')
        ->setType('bar')
        ->setHorizontal(true)
        ->setXAxis(['Jan', 'Feb', 'Mar'])
        ->setGrid(true)
        ->setDataset([
            [
                'name'  => 'Company A',
                'data'  =>  [500, 1000, 1900]
            ],
            [
                'name'  => 'Company B',
                'data'  => [300, 900, 1400]
            ],
            [
                'name'  => 'Company C',
                'data'  => [430, 245, 500]
            ]
        ])
        ->setStroke(1);

# Heatmap

$chart = (new LarapexChart)->setType('heatmap')
        ->setTitle('Total Users')
        ->setSubtitle('From January to March')
        ->setXAxis([
            'Jan', 'Feb', 'Mar'
        ])
        ->setDataset([
            [
                'name'  =>  'Users of Basic Plan',
                'data'  =>  [250, 700, 1200]
            ],
            [
                'name'  =>  'Users of Premium Plan',
                'data'  =>  [1000, 1124, 2000]
            ]
        ])
        ->setHeight(250)
        ->setGrid(false); 

# Change chart colors dinamically

Maybe you need a specific color in your chart, maybe the default config colors array does not reflect a specific need so there is a method to add an array of colors on the fly:

$chart = (new LarapexChart)->setTitle('Posts')
        ->setDataset([150, 120])
        ->setColors(['#ffc63b', '#ff6384'])
        ->setLabels(['Published', 'No Published']);

The setColors method accepts an array with hexadecimal colors as string and works on every chart so feel free to experiment with all chart setters.