默认条形图

条形图 - 图1

  1. <?php declare(strict_types = 1);
  2. $config = [
  3. 'path' => './tests',
  4. ];
  5. $dataHeader = [
  6. 'Number', 'Batch 1', 'Batch 2',
  7. ];
  8. $dataRows = [
  9. [2, 10, 30],
  10. [3, 40, 60],
  11. [4, 50, 70],
  12. [5, 20, 50],
  13. [6, 10, 40],
  14. [7, 50, 30],
  15. ];
  16. $fileObject = new \Vtiful\Kernel\Excel($config);
  17. $fileObject = $fileObject->fileName('tutorial.xlsx');
  18. $fileHandle = $fileObject->getHandle();
  19. $chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR);
  20. $chartResource = $chart
  21. // series(string $value [, string $category])
  22. ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
  23. ->seriesName('=Sheet1!$B$1')
  24. ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
  25. ->seriesName('=Sheet1!$C$1')
  26. ->axisNameX('Test number')
  27. ->axisNameY('Sample length (mm)')
  28. ->title('Results of sample analysis')
  29. ->style(11)
  30. ->toResource();
  31. $filePath = $fileObject
  32. ->header($dataHeader)
  33. ->data($dataRows)
  34. ->insertChart(0, 4, $chartResource)
  35. ->output();

堆积条形图

条形图 - 图2

  1. <?php declare(strict_types = 1);
  2. $config = [
  3. 'path' => './tests',
  4. ];
  5. $dataHeader = [
  6. 'Number', 'Batch 1', 'Batch 2',
  7. ];
  8. $dataRows = [
  9. [2, 10, 30],
  10. [3, 40, 60],
  11. [4, 50, 70],
  12. [5, 20, 50],
  13. [6, 10, 40],
  14. [7, 50, 30],
  15. ];
  16. $fileObject = new \Vtiful\Kernel\Excel($config);
  17. $fileObject = $fileObject->fileName('tutorial.xlsx');
  18. $fileHandle = $fileObject->getHandle();
  19. $chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR_STACKED);
  20. $chartResource = $chart
  21. // series(string $value [, string $category])
  22. ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
  23. ->seriesName('=Sheet1!$B$1')
  24. ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
  25. ->seriesName('=Sheet1!$C$1')
  26. ->axisNameX('Test number')
  27. ->axisNameY('Sample length (mm)')
  28. ->title('Results of sample analysis')
  29. ->style(12)
  30. ->toResource();
  31. $filePath = $fileObject
  32. ->header($dataHeader)
  33. ->data($dataRows)
  34. ->insertChart(0, 4, $chartResource)
  35. ->output();

百分比条形图

条形图 - 图3

  1. <?php declare(strict_types = 1);
  2. $config = [
  3. 'path' => './tests',
  4. ];
  5. $dataHeader = [
  6. 'Number', 'Batch 1', 'Batch 2',
  7. ];
  8. $dataRows = [
  9. [2, 10, 30],
  10. [3, 40, 60],
  11. [4, 50, 70],
  12. [5, 20, 50],
  13. [6, 10, 40],
  14. [7, 50, 30],
  15. ];
  16. $fileObject = new \Vtiful\Kernel\Excel($config);
  17. $fileObject = $fileObject->fileName('tutorial.xlsx');
  18. $fileHandle = $fileObject->getHandle();
  19. $chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_BAR_STACKED_PERCENT);
  20. $chartResource = $chart
  21. // series(string $value [, string $category])
  22. ->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
  23. ->seriesName('=Sheet1!$B$1')
  24. ->series('=Sheet1!$C$2:$C$7', '=Sheet1!$A$2:$A$7')
  25. ->seriesName('=Sheet1!$C$1')
  26. ->axisNameX('Test number')
  27. ->axisNameY('Sample length (mm)')
  28. ->title('Results of sample analysis')
  29. ->style(13)
  30. ->toResource();
  31. $filePath = $fileObject
  32. ->header($dataHeader)
  33. ->data($dataRows)
  34. ->insertChart(0, 4, $chartResource)
  35. ->output();