条形图

默认条形图

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

堆积条形图

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

百分比条形图

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