# Bar chart

## Default Bar Chart

![](https://665362659-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lmm53W9Z0JOSkMcC6BM%2F-LngHJdGtSLWIREGESld%2F-LngHZDmMjW5xsffnw8g%2Fchart_bar1.png?alt=media\&token=9f1e49d5-08b0-4f85-8594-8175a58d8843)

```php
<?php declare(strict_types = 1);

$config = [
    'path' => './tests',
];

$dataHeader = [
    'Number', 'Batch 1', 'Batch 2',
];

$dataRows   = [
    [2, 10, 30],
    [3, 40, 60],
    [4, 50, 70],
    [5, 20, 50],
    [6, 10, 40],
    [7, 50, 30],
];

$fileObject = new \Vtiful\Kernel\Excel($config);

$fileObject = $fileObject->fileName('tutorial.xlsx');
$fileHandle = $fileObject->getHandle();

$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR);

$chartResource = $chart
    // series(string $value [, string $category])
    ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$B$1')
    ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$C$1')
    ->axisNameX('Test number')
    ->axisNameY('Sample length (mm)')
    ->title('Results of sample analysis')
    ->style(11)
    ->toResource();

$filePath = $fileObject
    ->header($dataHeader)
    ->data($dataRows)
    ->insertChart(0, 4, $chartResource)
    ->output();
```

## stacked bar chart

![](https://665362659-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lmm53W9Z0JOSkMcC6BM%2F-LngHlK3IWPV5FBjL46l%2F-LngJc12cxIwZZmOIaqo%2Fchart_bar2.png?alt=media\&token=3dfe77e2-7e8f-45d6-8c8d-7d33422af47b)

```php
<?php declare(strict_types = 1);

$config = [
    'path' => './tests',
];

$dataHeader = [
    'Number', 'Batch 1', 'Batch 2',
];

$dataRows   = [
    [2, 10, 30],
    [3, 40, 60],
    [4, 50, 70],
    [5, 20, 50],
    [6, 10, 40],
    [7, 50, 30],
];

$fileObject = new \Vtiful\Kernel\Excel($config);

$fileObject = $fileObject->fileName('tutorial.xlsx');
$fileHandle = $fileObject->getHandle();

$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR_STACKED);

$chartResource = $chart
    // series(string $value [, string $category])
    ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$B$1')
    ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$C$1')
    ->axisNameX('Test number')
    ->axisNameY('Sample length (mm)')
    ->title('Results of sample analysis')
    ->style(12)
    ->toResource();

$filePath = $fileObject
    ->header($dataHeader)
    ->data($dataRows)
    ->insertChart(0, 4, $chartResource)
    ->output();
```

## percentage bar chart

![](https://665362659-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lmm53W9Z0JOSkMcC6BM%2F-LngHlK3IWPV5FBjL46l%2F-LngL3fdBGRHU1E0-yzM%2Fchart_bar3.png?alt=media\&token=f1f243f3-a8bb-4355-8347-cfce57451007)

```php
<?php declare(strict_types = 1);

$config = [
    'path' => './tests',
];

$dataHeader = [
    'Number', 'Batch 1', 'Batch 2',
];

$dataRows   = [
    [2, 10, 30],
    [3, 40, 60],
    [4, 50, 70],
    [5, 20, 50],
    [6, 10, 40],
    [7, 50, 30],
];

$fileObject = new \Vtiful\Kernel\Excel($config);

$fileObject = $fileObject->fileName('tutorial.xlsx');
$fileHandle = $fileObject->getHandle();

$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR_STACKED_PERCENT);

$chartResource = $chart
    // series(string $value [, string $category])
    ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$B$1')
    ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
    ->seriesName('=Sheet1!$C$1')
    ->axisNameX('Test number')
    ->axisNameY('Sample length (mm)')
    ->title('Results of sample analysis')
    ->style(13)
    ->toResource();

$filePath = $fileObject
    ->header($dataHeader)
    ->data($dataRows)
    ->insertChart(0, 4, $chartResource)
    ->output();
```
