doujia2090 2018-07-12 14:19
浏览 110
已采纳

laravel-chartjs没有显示任何内容

I am using the package found here to use chartjs on my laravel project, I followed the instructions to install it and tried to load the example into a blade file. The issue is, nothing is displaying. Below I attached the example code, does anyone have experience using this package and could point me in the right direction?

The way I installed it, in this order was:

composer require fx3costa/laravelchartjs
added Fx3costa\LaravelChartJs\Providers\ChartjsServiceProvider::class to Providers
npm install chart.js --save

The example method.

private function createchart(){
        $chartjs = app()->chartjs
        ->name('lineChartTest')
        ->type('line')
        ->size(['width' => 400, 'height' => 200])
        ->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July'])
        ->datasets([
            [
                "label" => "My First dataset",
                'backgroundColor' => "rgba(38, 185, 154, 0.31)",
                'borderColor' => "rgba(38, 185, 154, 0.7)",
                "pointBorderColor" => "rgba(38, 185, 154, 0.7)",
                "pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
                "pointHoverBackgroundColor" => "#fff",
                "pointHoverBorderColor" => "rgba(220,220,220,1)",
                'data' => [65, 59, 80, 81, 56, 55, 40],
            ],
            [
                "label" => "My Second dataset",
                'backgroundColor' => "rgba(38, 185, 154, 0.31)",
                'borderColor' => "rgba(38, 185, 154, 0.7)",
                "pointBorderColor" => "rgba(38, 185, 154, 0.7)",
                "pointBackgroundColor" => "rgba(38, 185, 154, 0.7)",
                "pointHoverBackgroundColor" => "#fff",
                "pointHoverBorderColor" => "rgba(220,220,220,1)",
                'data' => [12, 33, 44, 44, 55, 23, 40],
            ]
        ])
        ->options([]);


        return $chartjs;

blade file:

<div style="width:75%;">
    {!! $chartjs->render() !!}
</div>
  • 写回答

1条回答 默认 最新

  • duandingyou3331 2018-07-12 15:43
    关注

    The problem is that command npm install chart.js --save only installs chartjs libray (in /node_modules dir), you also need to integrate it with your project, for example with script tag placed in <head>:

    <script src="path/to/chartjs/dist/Chart.js"></script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题