亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 laravel consoletvs 圖表中使用 sum 和 groupBy

如何在 laravel consoletvs 圖表中使用 sum 和 groupBy

PHP
揚帆大魚 2022-01-08 20:25:22
$sumBrpro = DB::table('productions')              ->select([DB::raw('sum(montant_pro) as totalpro'),'branche'])              ->groupBy('branche')              ->get();如何在 consoletvs 圖表中傳遞不同的值,這會在 index-> 分支處引發錯誤。謝謝您的幫助foreach($sumBrpro as $index){      $chartbr = Charts::create('bar', 'highcharts')                       ->title("production")                       ->labels($index->branche)                       ->values($index->totalpro)                       ->dimensions(1000,500)                       ->responsive(true);}Vue<div>                    {!! $chartbr->html() !!}                </div>```
查看完整描述

1 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

根據Charts外觀的用法,我假設您使用的是consoletvs/charts包的5.x 版。


這個包需要數組作為labels()andvalues()方法的參數。在render()最終調用的方法中,傳遞給labels()andvalues()方法的值將傳遞給count(),所以如果它們不可數,你會得到一個錯誤(在 PHP >= 7.2 中)。


更新您的代碼以將數組傳遞給labels()andvalues()方法。


foreach ($sumBrpro as $index) {

    $chartbr = Charts::create('bar', 'highcharts')

        ->title("production")

        ->labels([$index->branche])

        ->values([$index->totalpro])

        ->dimensions(1000,500)

        ->responsive(true);

}

但是,我假設您正在嘗試創建一個圖表,其中所有branches 都是標簽,所有totalpros 都是值。在這種情況下,您正在尋找更多類似這樣的東西:


$chartbr = Charts::create('bar', 'highcharts')

    ->title("production")

    ->labels($sumBrpro->pluck('branche')->all())

    ->values($sumBrpro->pluck('totalpro')->all())

    ->dimensions(1000,500)

    ->responsive(true);


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 144 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號