Skip to content

Commit d82218c

Browse files
committed
minor #42 [Chart] Add a small example how to set options (Nyholm)
This PR was merged into the main branch. Discussion ---------- [Chart] Add a small example how to set options | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | | License | MIT Adding a small example how to set chart options. The docs for this example is [here](https://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration) and personally I find it next to impossible to discover what options are available... This example may help people just a bit. Commits ------- 3054a29 [Chart.js] Add a small example how to set options
2 parents b181b90 + 3054a29 commit d82218c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Chartjs/Model/Chart.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ public function setData(array $data): self
4949
}
5050

5151
/**
52+
* Sets Chart.js options.
53+
*
54+
* @see https://www.chartjs.org/docs/latest/
55+
*
56+
* <code>
57+
* $chart->setOptions([
58+
* 'scales' => [
59+
* 'yAxes' => [
60+
* ['ticks' => ['min' => 0, 'max' => 100]],
61+
* ]
62+
* ]
63+
* ]);
64+
* </code>
65+
*
5266
* @return $this
5367
*/
5468
public function setOptions(array $options): self

src/Chartjs/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ class HomeController extends AbstractController
4747
],
4848
]);
4949

50-
$chart->setOptions([/* ... */]);
50+
$chart->setOptions([
51+
'scales' => [
52+
'yAxes' => [
53+
['ticks' => ['min' => 0, 'max' => 100]],
54+
],
55+
],
56+
]);
5157

5258
return $this->render('home/index.html.twig', [
5359
'chart' => $chart,

0 commit comments

Comments
 (0)