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

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 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示