├── .php_cs
├── Chart.php
├── ChartAsset.php
├── LICENSE.md
├── README.md
└── composer.json
/.php_cs:
--------------------------------------------------------------------------------
1 | exclude([
5 | 'vendor',
6 | 'runtime',
7 | 'tests/_output',
8 | 'tests/_support',
9 | ])
10 | ->in([__DIR__]);
11 |
12 | $config = PhpCsFixer\Config::create()
13 | ->setUsingCache(false)
14 | ->setRules([
15 | '@Symfony' => true,
16 | 'phpdoc_align' => false,
17 | 'phpdoc_summary' => false,
18 | 'phpdoc_inline_tag' => false,
19 | 'pre_increment' => false,
20 | 'heredoc_to_nowdoc' => false,
21 | 'cast_spaces' => false,
22 | 'include' => false,
23 | 'phpdoc_no_package' => false,
24 | 'concat_space' => ['spacing' => 'one'],
25 | 'ordered_imports' => true,
26 | 'array_syntax' => ['syntax' => 'short'],
27 | ])
28 | ->setFinder($finder);
29 |
30 | return $config;
31 |
--------------------------------------------------------------------------------
/Chart.php:
--------------------------------------------------------------------------------
1 | registerAssets();
22 |
23 | return Html::tag('div', '', ['id' => $this->options['id']]);
24 | }
25 |
26 | /**
27 | * Register assets
28 | */
29 | protected function registerAssets()
30 | {
31 | $id = $this->options['id'];
32 | $view = $this->getView();
33 | ChartAsset::register($view);
34 | $view->registerJs("var {$id} = c3.generate({$this->getClientOptions()});", $view::POS_END);
35 | }
36 |
37 | /**
38 | * Get client options in the json format
39 | *
40 | * @return string
41 | */
42 | protected function getClientOptions()
43 | {
44 | $this->clientOptions['bindto'] = '#' . $this->options['id'];
45 |
46 | return Json::encode($this->clientOptions);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ChartAsset.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Yii2 Chart Widget
6 |
7 |
8 |
9 | Yii2 wrapper for D3-based reusable chart library
10 |
11 | [](https://packagist.org/packages/yii2mod/yii2-c3-chart) [](https://packagist.org/packages/yii2mod/yii2-c3-chart) [](https://packagist.org/packages/yii2mod/yii2-c3-chart)
12 | [](https://travis-ci.org/yii2mod/yii2-c3-chart)
13 |
14 | Installation
15 | ------------
16 |
17 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
18 |
19 | Either run
20 |
21 | ```
22 | php composer.phar require --prefer-dist yii2mod/yii2-c3-chart "*"
23 | ```
24 |
25 | or add
26 |
27 | ```
28 | "yii2mod/yii2-c3-chart": "*"
29 | ```
30 |
31 | to the require section of your `composer.json` file.
32 |
33 |
34 | Usage
35 | -----
36 |
37 | Once the extension is installed, simply use it in your code by :
38 |
39 | ```php
40 | [
42 | 'id' => 'popularity_chart'
43 | ],
44 | 'clientOptions' => [
45 | 'data' => [
46 | 'x' => 'x',
47 | 'columns' => [
48 | ['x', 'week 1', 'week 2', 'week 3', 'week 4'],
49 | ['Popularity', 10, 20, 30, 50]
50 | ],
51 | 'colors' => [
52 | 'Popularity' => '#4EB269',
53 | ],
54 | ],
55 | 'axis' => [
56 | 'x' => [
57 | 'label' => 'Month',
58 | 'type' => 'category'
59 | ],
60 | 'y' => [
61 | 'label' => [
62 | 'text' => 'Popularity',
63 | 'position' => 'outer-top'
64 | ],
65 | 'min' => 0,
66 | 'max' => 100,
67 | 'padding' => ['top' => 10, 'bottom' => 0]
68 | ]
69 | ]
70 | ]
71 | ]); ?>
72 | ```
73 |
74 | Chart Examples
75 | ----------------
76 | You can find them on the [examples page](http://c3js.org/examples.html)
77 |
78 |
79 | Chart Options
80 | ----------------
81 | You can find them on the [options page](http://c3js.org/reference.html)
82 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yii2mod/yii2-c3-chart",
3 | "description": "Yii2 wrapper for D3-based reusable chart library",
4 | "type": "yii2-extension",
5 | "keywords": [
6 | "yii2",
7 | "yii2 c3.js",
8 | "yii2 c3 chart"
9 | ],
10 | "license": "MIT",
11 | "authors": [
12 | {
13 | "name": "Igor Chepurnoy",
14 | "email": "igorzfort@gmail.com"
15 | }
16 | ],
17 | "require": {
18 | "yiisoft/yii2": "*",
19 | "yiisoft/yii2-bootstrap": "*",
20 | "bower-asset/c3": "*"
21 | },
22 | "require-dev": {
23 | "friendsofphp/php-cs-fixer": "~2.0"
24 | },
25 | "autoload": {
26 | "psr-4": {
27 | "yii2mod\\c3\\chart\\": ""
28 | }
29 | },
30 | "repositories": [
31 | {
32 | "type": "composer",
33 | "url": "https://asset-packagist.org"
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------