├── .gitignore ├── composer.json ├── readme.md └── src ├── Classes └── Presenters │ ├── ChartPresenter.php │ ├── ContainerPresenter.php │ ├── InitJsPresenter.php │ └── JsTransformerPresenter.php ├── Config └── highchart.php ├── Facade.php ├── Highcharts.php └── Provider.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /.idea 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "muhamadrezaar/highcharts", 3 | "description": "Laravel Highcarts Packages", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords" : ["laravel" , "highcharts","packages"], 7 | "authors": [ 8 | { 9 | "name": "Muhamad Reza Abdul Rohim", 10 | "email": "reza.wikrama3@gmail.com" 11 | } 12 | ], 13 | "minimum-stability": "stable", 14 | "require": {}, 15 | "autoload": { 16 | "psr-4": { 17 | "RezaAr\\Highcharts\\": "src/" 18 | } 19 | }, 20 | "extra": { 21 | "laravel": { 22 | "providers": [ 23 | "RezaAr\\Highcharts\\Provider" 24 | ], 25 | "aliases": { 26 | "Chart": "RezaAr\\Highcharts\\Facade" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Laravel 5 Highcharts Packages 2 | 3 | [](https://packagist.org/packages/muhamadrezaar/highcharts) 4 | [](https://packagist.org/packages/muhamadrezaar/highcharts) 5 | [](https://github.com/julles/laravel-highcharts/releases) 6 | [](https://github.styleci.io/repos/49810531/shield) 7 | 8 | Package Highcharts for Laravel 5 9 | 10 | ### Installations 11 | 12 | Add Package to composer.json 13 | 14 | ```sh 15 | composer require muhamadrezaar/highcharts:dev-master 16 | ``` 17 | In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider and facade in config/app.php file: 18 | 19 | Provider : 20 | ```sh 21 | RezaAr\Highcharts\Provider::class, 22 | ``` 23 | Facade : 24 | ```sh 25 | 'Chart' => RezaAr\Highcharts\Facade::class, 26 | ``` 27 | 28 | then publish the config 29 | 30 | ``` sh 31 | php artisan vendor:publish 32 | ``` 33 | 34 | ### Basic Usage 35 | 36 | In Controller or Other Class 37 | 38 | ```sh 39 | 40 | 'Voting ballon d`or 2018', 43 | ]) 44 | ->chart([ 45 | 'type' => 'line', // pie , columnt ect 46 | 'renderTo' => 'chart1', // render the chart into your div with id 47 | ]) 48 | ->subtitle([ 49 | 'text' => 'This Subtitle', 50 | ]) 51 | ->colors([ 52 | '#0c2959' 53 | ]) 54 | ->xaxis([ 55 | 'categories' => [ 56 | 'Alex Turner', 57 | 'Julian Casablancas', 58 | 'Bambang Pamungkas', 59 | 'Mbah Surip', 60 | ], 61 | 'labels' => [ 62 | 'rotation' => 15, 63 | 'align' => 'top', 64 | 'formatter' => 'startJs:function(){return this.value + " (Footbal Player)"}:endJs', 65 | // use 'startJs:yourjavasscripthere:endJs' 66 | ], 67 | ]) 68 | ->yaxis([ 69 | 'text' => 'This Y Axis', 70 | ]) 71 | ->legend([ 72 | 'layout' => 'vertikal', 73 | 'align' => 'right', 74 | 'verticalAlign' => 'middle', 75 | ]) 76 | ->series( 77 | [ 78 | [ 79 | 'name' => 'Voting', 80 | 'data' => [43934, 52503, 57177, 69658], 81 | // 'color' => '#0c2959', 82 | ], 83 | ] 84 | ) 85 | ->display(); 86 | 87 | return view('welcome', [ 88 | 'chart1' => $chart1, 89 | ]); 90 | 91 | 92 | ?> 93 | ``` 94 | In Blade 95 | 96 | ```sh 97 | 98 |
99 | 100 | {!! $chart1 !!} 101 | 102 | ``` 103 | Output : 104 | 105 |  106 | 107 | 108 | the package will generate this code in yout view : 109 | 110 | ``` sh 111 | 112 | 113 | 114 | 115 | 116 | 148 | 149 | 150 | ``` 151 | 152 | cdn highcharts.js and others js only generated one time 153 | 154 | ## License 155 | 156 | https://reza.mit-license.org/ 157 | 158 | Buy me a cup of coffee 159 | https://trakteer.id/mreza.id 160 | 161 | -------------------------------------------------------------------------------- /src/Classes/Presenters/ChartPresenter.php: -------------------------------------------------------------------------------- 1 | display = ''; 14 | $this->js = new InitJsPresenter(); 15 | $this->js->highchart = config('highchart.series_label_js'); 16 | $this->js->seriesLabel = config('highchart.highchart_js'); 17 | $this->js->exporting = config('highchart.exporting_js'); 18 | $this->js->exportData = config('highchart.export_data_js'); 19 | $this->container = new ContainerPresenter(); 20 | $this->transform = new JsTransformerPresenter(); 21 | $this->title = []; 22 | } 23 | 24 | public function highcart_js($bool = true) 25 | { 26 | $this->js->highchart = $bool; 27 | 28 | return $this; 29 | } 30 | 31 | public function series_label_js($bool = true) 32 | { 33 | $this->js->seriesLabel = $bool; 34 | 35 | return $this; 36 | } 37 | 38 | public function exporting_js($bool = true) 39 | { 40 | $this->js->exporting = $bool; 41 | 42 | return $this; 43 | } 44 | 45 | public function export_data_js($bool = true) 46 | { 47 | $this->js->exportData = $bool; 48 | 49 | return $this; 50 | } 51 | 52 | public function getInitJs() 53 | { 54 | $this->display .= $this->js->generate(); 55 | $this->js->init = false; 56 | 57 | return $this; 58 | } 59 | 60 | public function container($container = 'container') 61 | { 62 | $this->transform->container = $container; 63 | 64 | return $this; 65 | } 66 | 67 | public function title($title = []) 68 | { 69 | $this->transform->title = $title; 70 | 71 | return $this; 72 | } 73 | 74 | public function subtitle($subtitle = []) 75 | { 76 | $this->transform->subtitle = $subtitle; 77 | 78 | return $this; 79 | } 80 | 81 | public function yaxis($data = []) 82 | { 83 | $this->transform->yAxis = $data; 84 | 85 | return $this; 86 | } 87 | 88 | public function xaxis($data = []) 89 | { 90 | $this->transform->xAxis = $data; 91 | 92 | return $this; 93 | } 94 | 95 | public function legend($legend = []) 96 | { 97 | $this->transform->legend = $legend; 98 | 99 | return $this; 100 | } 101 | 102 | public function plotOptions($plotOptions = []) 103 | { 104 | $this->transform->plotOptions = $plotOptions; 105 | 106 | return $this; 107 | } 108 | 109 | public function tooltip($tooltip = []) 110 | { 111 | $this->transform->tooltip = $tooltip; 112 | 113 | return $this; 114 | } 115 | 116 | public function series($series = []) 117 | { 118 | $this->transform->series = $series; 119 | 120 | return $this; 121 | } 122 | 123 | public function chart($series = []) 124 | { 125 | $this->transform->chart = $series; 126 | 127 | return $this; 128 | } 129 | 130 | public function colors($series = []) 131 | { 132 | $this->transform->colors = $series; 133 | 134 | return $this; 135 | } 136 | 137 | public function credits($credits = []) 138 | { 139 | $this->transform->credits = $credits; 140 | 141 | return $this; 142 | } 143 | 144 | public function getTransform() 145 | { 146 | $this->display .= $this->transform->transform(); 147 | 148 | return $this; 149 | } 150 | 151 | public function tes($tes) 152 | { 153 | $this->display .= $tes; 154 | 155 | return $this; 156 | } 157 | 158 | public function display() 159 | { 160 | $this->getInitJs(); 161 | $this->getTransform(); 162 | $display = $this->display; 163 | $this->display = null; 164 | 165 | return $display; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/Classes/Presenters/ContainerPresenter.php: -------------------------------------------------------------------------------- 1 | container = ''; 12 | } 13 | 14 | public function container($id = 'container') 15 | { 16 | $this->container = ''; 17 | 18 | return $this->container; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Classes/Presenters/InitJsPresenter.php: -------------------------------------------------------------------------------- 1 | generate = null; 17 | } 18 | 19 | public function init_js() 20 | { 21 | $init = ''; 22 | 23 | if ($this->highchart == true) { 24 | $this->highchart = ''; 25 | } 26 | 27 | if ($this->seriesLabel == true) { 28 | $this->seriesLabel = ''; 29 | } 30 | 31 | if ($this->exporting == true) { 32 | $this->exporting = ''; 33 | } 34 | 35 | if ($this->exportData == true) { 36 | $this->exportData = ''; 37 | } 38 | 39 | if ($this->init !== false) { 40 | $init = $this->highchart. 41 | $this->seriesLabel. 42 | $this->exporting. 43 | $this->exportData; 44 | } 45 | 46 | return $init; 47 | } 48 | 49 | public function generate() 50 | { 51 | $generate = $this->init_js(); 52 | $this->generate = null; 53 | 54 | return $generate; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Classes/Presenters/JsTransformerPresenter.php: -------------------------------------------------------------------------------- 1 | transform = ''; 24 | } 25 | 26 | public function encode_title() 27 | { 28 | $data = $this->title; 29 | 30 | $this->title = !empty($data) ? 'title: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 31 | 32 | return $this; 33 | } 34 | 35 | public function encode_sub_title() 36 | { 37 | $data = $this->subtitle; 38 | 39 | $this->subtitle = !empty($data) ? 'subtitle: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 40 | 41 | return $this; 42 | } 43 | 44 | public function encode_y_axis() 45 | { 46 | $data = $this->yAxis; 47 | 48 | $this->yAxis = !empty($data) ? 'yAxis: '.json_encode($data).',' : null; 49 | 50 | return $this; 51 | } 52 | 53 | public function encode_x_axis() 54 | { 55 | $data = $this->xAxis; 56 | $this->xAxis = !empty($data) ? 'xAxis: '.json_encode($data).',' : null; 57 | 58 | return $this; 59 | } 60 | 61 | public function encode_legend() 62 | { 63 | $data = $this->legend; 64 | 65 | $this->legend = !empty($data) ? 'legend: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 66 | 67 | return $this; 68 | } 69 | 70 | public function encode_plot_options() 71 | { 72 | $data = $this->plotOptions; 73 | 74 | $this->plotOptions = !empty($data) ? 'plotOptions: '.json_encode($data).',' : null; 75 | 76 | return $this; 77 | } 78 | 79 | public function encode_tooltip() 80 | { 81 | $data = $this->tooltip; 82 | 83 | $this->tooltip = !empty($data) ? 'tooltip: '.json_encode($data).',' : null; 84 | 85 | return $this; 86 | } 87 | 88 | public function encode_series() 89 | { 90 | $data = $this->series; 91 | 92 | $this->series = !empty($data) ? 'series: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 93 | 94 | return $this; 95 | } 96 | 97 | public function encode_chart() 98 | { 99 | $data = $this->chart; 100 | 101 | $this->chart = !empty($data) ? 'chart: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 102 | 103 | return $this; 104 | } 105 | 106 | public function encode_colors() 107 | { 108 | $data = $this->colors; 109 | $this->colors = !empty($data) ? 'colors: '.json_encode($data).',' : null; 110 | 111 | return $this; 112 | } 113 | 114 | public function credits() 115 | { 116 | $data = $this->credits; 117 | $this->credits = !empty($data) ? 'credits: '.json_encode($data, JSON_UNESCAPED_UNICODE).',' : null; 118 | 119 | return $this; 120 | } 121 | 122 | public function replacer($string) 123 | { 124 | $chars = [ 125 | '\\n', 126 | '\\t', 127 | '"startJs:', 128 | '}"', 129 | '\\', 130 | ':endJs"', 131 | ]; 132 | $replace = ['', '', '', '', '']; 133 | 134 | return str_replace($chars, $replace, $string); 135 | } 136 | 137 | public function transform() 138 | { 139 | $this->encode_title(); 140 | $this->encode_sub_title(); 141 | $this->encode_y_axis(); 142 | $this->encode_x_axis(); 143 | $this->encode_legend(); 144 | $this->encode_plot_options(); 145 | $this->encode_tooltip(); 146 | $this->encode_series(); 147 | $this->encode_chart(); 148 | $this->encode_colors(); 149 | $this->credits(); 150 | 151 | $allString = $this->title. 152 | $this->subtitle. 153 | $this->yAxis. 154 | $this->xAxis. 155 | $this->legend. 156 | $this->plotOptions. 157 | $this->tooltip. 158 | $this->series. 159 | $this->chart. 160 | $this->colors. 161 | $this->credits; 162 | 163 | $allString = substr($allString, 0, -1); 164 | $allString = $this->replacer($allString); 165 | $generate = ''; 168 | 169 | return $generate; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/Config/highchart.php: -------------------------------------------------------------------------------- 1 | true, 5 | 'series_label_js' => true, 6 | 'exporting_js' => true, 7 | 'export_data_js' => true, 8 | ]; 9 | -------------------------------------------------------------------------------- /src/Facade.php: -------------------------------------------------------------------------------- 1 | publishes([ 12 | __DIR__.'/Config/highchart.php' => config_path('highchart.php'), 13 | ], 'highchart_config'); 14 | } 15 | 16 | public function register() 17 | { 18 | $this->mergeConfigFrom( 19 | __DIR__.'/Config/highchart.php', 'highchart' 20 | ); 21 | 22 | $this->app->bind('register-highcharts', function () { 23 | return new Highcharts(); 24 | }); 25 | } 26 | } 27 | --------------------------------------------------------------------------------