在 Laravel 图表中找不到“ConsoleTVs\Charts\Facades\Charts”类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53464456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:10:25  来源:igfitidea点击:

Class 'ConsoleTVs\Charts\Facades\Charts' not found in laravel Charts

laravelchartshighcharts

提问by Pasindu Senarath

i'm trying to render a chart with data in database using laravel. but i'm getting this error

我正在尝试使用 laravel 渲染包含数据库中数据的图表。但我收到这个错误

    **Class 'ConsoleTVs\Charts\Facades\Charts' not found**

but i already add requried providers to app.php,

但我已经将所需的提供程序添加到 app.php,

    ConsoleTVs\Charts\ChartsServiceProvider::class,
    'Charts' => ConsoleTVs\Charts\Facades\Charts::class

here is my controller,

这是我的控制器,

class DashboardController extends Controller
{
    public function admin()
    {

        $suppliers = SupplierData::all();
        $repcounter= SalesRep::count();
        $totalsales= SalesData::count();
        $totalrevenue=SalesData::sum('total_price');

        $chartdata = SalesData::selectRaw('COUNT(*) as count, YEAR(dateOfSale) year, MONTH(dateofSale) month')
            ->groupBy('year', 'month')
            ->get();
        $chart=Charts::database($chartdata,'bar','highcharts')
            ->title("Sales Details")
            ->elementLabel("Total Sales")
            ->dimensions(1000,500)
            ->responsive(false);

        return view('dashboard', compact('suppliers','repcounter','totalsales','totalrevenue','chart'));

and here is my html part,

这是我的 html 部分,

 <div>
   {!! $chart->render() !!}
                    </div>

so can anyone help with this?

任何人都可以帮助解决这个问题吗?

I follow this video tutorial. https://www.youtube.com/watch?v=yAGVB4ZIQ4o

我按照这个视频教程。https://www.youtube.com/watch?v=yAGVB4ZIQ4o

回答by Ijas Ameenudeen

The package, ConsoleTVs/Charts v6, doesn't provide a Facade approach.

ConsoleTVs/Charts v6不提供 Facade 方法。

Please check charts.erik.cat/create_charts.html#create-a-chart-classto start creating charts using the ConsoleTVs/Charts v6

请检查charts.erik.cat/create_charts.html#create-a-chart-class以开始使用ConsoleTVs/Charts v6创建图表

The video tutorial you are following is using ConsoleTVs/Charts v5. It does support Facade approach.

您所关注的视频教程使用的是ConsoleTVs/Charts v5。它确实支持 Facade 方法。

If you want to continue with the video, You need to downgrade the package.

如果您想继续观看视频,您需要将软件包降级。

Remove v6

删除 v6

composer remove consoletvs/charts

And install v5

并安装 v5

composer require "consoletvs/charts:5.*"

Since you are using latest version of the Laravel, I highly recommend to use the latest version of consoletvs/charts.

由于您使用的是最新版本的 Laravel,我强烈建议您使用最新版本的consoletvs/charts