在搜索了大约2个小时的文档并没有找到答案(https://charts.erik.cat/)之后,也许有人会帮我解决这个问题……我正在使用Laravel Charts chart.js库。如何使该列顶部显示数据标签?就像这张图片上的DC coulmn:
这是我的代码:
<?php
namespace App\Http\Controllers;
use App\Content;
use App\Charts\UserLineChart;
use Charts;
use Illuminate\Http\Request;
class ChartController extends Controller
{
public function index(Request $request)
{
$content = Content::where('vei_sn', '23333')->get();
if ($request->has('date_from') && $request->input('date_from') != '' && $request->has('date_to') && $request->input('date_to') != '') {
$datefrom = $request->input('date_from');
$dateto = $request->input('date_to');
$content = $content->whereBetween('op_date', [$datefrom, $dateto]);
}
$OBD = $content->where('con_type', 'OBD')->count();
$DC = $content->where('con_type', 'DC')->count();
$BSL = $content->where('con_type', 'BSL')->count();
$content = $content->pluck('con_type', 'con_type');
$pChart = new UserLineChart;
$bChart = new UserLineChart;
$pChart->labels($content->values())->minimalist($display = true);
$bChart->labels($content->values());
$pChart->dataset('Connections', 'pie', [$OBD, $DC, $BSL]);
$bChart->dataset('Connections', 'bar', [$OBD, $DC, $BSL])->options([
'fill' => false,
]);
return view('chart.index', compact('pChart', 'bChart'));
}
}