Laravel Charts 图表 使用

composer require consoletvs/charts:6.*

可能报错

zsh: no matches found: consoletvs/charts:6.*

此时,需要在 ~/.zshrc 添加

alias composer='noglob composer'
composer require consoletvs/charts:6.*
php artisan vendor:publish --tag=charts_config
php artisan make:chart SampleChart

然后在控制器调用SampleChart类

use App\Charts\SampleChart;
$chart = new SampleChart;
$chart->labels(['One', 'Two', 'Three', 'Four']);
$chart->dataset('My dataset', 'line', [1, 2, 3, 4]);
$chart->dataset('My dataset 2', 'line', [4, 3, 2, 1]);
return view('sample_view', compact('chart'));

最后在HTML渲染

{!! $chart->container() !!}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
{!! $chart->script() !!}
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3

第一次安装composer包报这个错

$ composer require consoletvs/charts:6.*
    1/8:        https://packagist.laravel-china.org/p/provider-latest$8330e6c47f0d7928991cc29870036aad273a568fbd7bbc507356bbd5d48c8466.json
    2/8:        https://packagist.laravel-china.org/p/provider-2018-10$0e1d6b404e963f8180f7e3bfb719d80f547b1e78a2b2932a00cb7d976faff11d.json
    3/8:        https://packagist.laravel-china.org/p/provider-2018-01$ba7b7983a3c1301d163f90d298d6e0d606b3a895a32a7c847591cb9c1ee056b8.json
    4/8:        https://packagist.laravel-china.org/p/provider-2018-04$312fbc0c21e13dafb9783c7dd9f8ffdaf59c3857a7f9973247136070e75374fd.json
    5/8:        https://packagist.laravel-china.org/p/provider-2018-07$416f0a818f89f18a25b366ff7c8b8c3b7cf29833cf18e3dcd1b0f18495020ef1.json
    6/8:        https://packagist.laravel-china.org/p/provider-2016$0236be99dd3571ad95d3a0ceb7f3988286a5ccc50c573194633f8d8276767a6d.json
    7/8:        https://packagist.laravel-china.org/p/provider-2015$5771d431334174a36135b01b11b4b3250cc810539ed792701516780e38858a3d.json
    8/8:        https://packagist.laravel-china.org/p/provider-2017$4fa82b14f6b97fb059cdf0bf51bfd586631b1c4d058e51eb1b15327b7b10c1ae.json
    Finished: success: 8, skipped: 0, failure: 0, total: 8
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

VirtualAlloc() failed: [0x00000008] ▒洢▒ռ䲻▒㣬▒޷▒▒▒▒▒▒▒▒▒

VirtualFree() failed: [0x000001e7] ▒▒ͼ▒▒▒▒▒▒Ч▒ĵ▒ַ▒▒

VirtualAlloc() failed: [0x00000008] ▒洢▒ռ䲻▒㣬▒޷▒▒▒▒▒▒▒▒▒

VirtualFree() failed: [0x000001e7] ▒▒ͼ▒▒▒▒▒▒Ч▒ĵ▒ַ▒▒

PHP Fatal error:  Out of memory (allocated 952107008) (tried to allocate 4096 bytes) in phar://D:/php_study/PHPTutorial/php/php-7.1.13-nts/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

Fatal error: Out of memory (allocated 952107008) (tried to allocate 4096 bytes) in phar://D:/php_study/PHPTutorial/php/php-7.1.13-nts/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
5年前 评论

@lovecn 你这个报错PHP内存不足,phpinfo()查看下memory_limit配置,设置大点试试。

memory_limit    128M    128M
5年前 评论

修改 app\Providers\AppServiceProvider.php 好了

public function boot()
    {
        Schema::defaultStringLength(191);
        ini_set('memory_limit', '1G');
    }
5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!