0 レビュー
1 回答
php-Laravel5.5コンソールTV棒グラフ複数のデータセットとラベルのハイチャート
このConsoleTVチャートパッケージを使用したLaravel5.5アプリがあります。barchartを使用してデータ月次レポートベース。以下のクエリがあります。
$dt = Carbon::now()->year;
$anRequest = AnalysisRequest::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y'))->orderBy('service_id')
->get();
そして私のチャート
$barChart = Charts::database($anRequest, 'bar', 'highcharts')
->title("Monthly service request")
->elementLabel("Total requests")
->dimensions(1000, 500)
->responsive(false)
->groupByMonth(date('Y'), true);
このコードは完全に正常に機能しており、すべてのデータを月までに表示しますが、別の dataSets
または{-codeを追加するにはどうすればよいですか。 -4}
を視覚化するためのデータセットを1つだけ持つのではなく。
たとえば、 AnalysisRequest からの別のクエリがありますが、特定のリソースがあります。
multi
を使用した以下のサンプルコードクエリ
$tags_jan = DB::table('tags')->whereYear('created_at', $dt)->whereMonth('created_at', '1')->count();
$tags_feb = DB::table('tags')->whereYear('created_at', $dt)->whereMonth('created_at', '2')->count();
$tags_mar = DB::table('tags')->whereYear('created_at', $dt)->whereMonth('created_at', '3')->count();
// and the list goes on which is bad
multi
を使用したチャート $chart = Charts::multi('bar', 'highcharts')
// Setup the chart settings
->title("Total Reports for this year")
// A dimension of 0 means it will take 100% of the space
->dimensions(0, 400) // Width x Height
// This defines a preset of colors already done:)
// ->template("material")
// ->responsive(true)
// You could always set them manually
// ->colors(['#2196F3', '#F44336', '#FFC107'])
// Setup the diferent datasets (this is a multi chart)
->colors(['green', 'aqua', 'red', 'yellow'])
->dataset('Ads', [$ads_jan,$ads_feb,$ads_mar,$ads_apr,$ads_may,$ads_june,$ads_july,$ads_aug,$ads_sept,$ads_oct,$ads_nov,$ads_dec])
->dataset('Channels', [$channels_jan,$channels_feb,$channels_mar,$channels_apr,$channels_may,$channels_june,$channels_july,$channels_aug,$channels_sept,$channels_oct,$channels_nov,$channels_dec])
->dataset('Shows', [$shows_jan,$shows_feb,$shows_mar,$shows_apr,$shows_may,$shows_june,$shows_july,$shows_aug,$shows_sept,$shows_oct,$shows_nov,$shows_dec])
->dataset('Tags', [$tags_jan,$tags_feb,$tags_mar,$tags_apr,$tags_may,$tags_june,$tags_july,$tags_aug,$tags_sept,$tags_oct,$tags_nov,$tags_dec])
上記のコードも正常に機能しますが、変数でわかるように、今年は毎月クエリを実行していますが、これはあまり良くありません。このクエリまたは複数のdataSetsを使用してこれを解決する別の方法を簡略化するにはどうすればよいですか?
誰かが助けてくれるかどうか感謝します。 よろしくお願いします。
わからない
0
レビュー
答え :
解決策:
データベースにクエリを実行し、同じビューにさまざまなグラフを投稿したい場合は、次のコードを追加できます。このコードを使用して、棒グラフと折れ線グラフをプロットしました。以下に指定されているのと同じグラフ........データセットの位置2の線と棒を見てください
$chart = new unclaimed;
$chart->labels( $days );
$chart->dataset('Daily Visitors Bar', 'bar', $totalNumber )->color('white')->backgroundColor(['#009900','#8a8a5c','#f1c40f','#e67e22','#16a085','#2980b9']);
$chart->dataset('Daily Visitors Line', 'line', $totalNumber )->color('black') ->fill(false)->backgroundColor(['##8a8a5c','009900','#f1c40f','#e67e22','#16a085','#2980b9']);
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。