【发布时间】:2020-04-18 06:47:38
【问题描述】:
我已经做了很多研究,但我无法弄清楚如何在标签徽章中输入百分比,如下图所示。
更新: 我正在使用这个 laravel 包装器:https://github.com/ConsoleTVs/Charts 这也是我不想让观众感到困惑的原因。 我只想知道选项的名称.. 我的代码是这样的:
$perTopicChart = (new AnsweredPerTopic);//->percentageInnerCutout(70);
$perTopicChart->options([
"events" => [],
"legend" => [
"labels" => [
"defaultFontFamily" => "Tahoma",
"fontSize" => 16,
],
"position" => 'bottom'
],
"cutoutPercentage" => 80,
'tooltips' => [
"show" => true
]
])->displayAxes(0);
// put the labels (keys)
$perTopicChart->labels($keys->map(function ($q) use ($perTopic) {
$topic = Topic::find($q);
$str = $topic->name;
foreach ($perTopic as $key => $value) {
if ($key == $q) {
$str .= ' ' . round($value) . '%';
}
}
return "topic name " . '-'. $topic->id;
})->push('other'))
->options([]);
// get random color
// $color = RandomColor::many(count($keys), array(
// 'luminosity' => 'bright',
// 'hue' => ['pink', 'green', 'orange'] // e.g. 'rgb(225,200,20)'
// ));
$color = [
"#38c172",
"#9F9",
"#Fa0",
"pink",
"red",
];
$perTopicChart->dataset("Practice per Category", "doughnut", $values->map(function ($q) {
return round($q);
})->push($remainingPercenteg))
->backgroundColor($color)
->options([
'borderWidth' => 2.5,
]);
第一张图片是当前结果,第二张是我想要的。 提前致谢。
【问题讨论】:
-
你的代码是?你试过什么?你在输出中得到了什么?
-
感谢 kenny 提供反馈,我更新了问题,感谢任何帮助。
-
即使我为此进行了很多研究,也找不到任何东西,只是想到了 hack 之类的东西,而不是让 chartjs 绘制图例,我们应该将它绘制在我们身边。就像从图表 js 中获取图例的 html 并将其绘制在我们这边。这更像是一种黑客行为。如果你想要它的代码,我可以给你一个例子
标签: javascript php laravel chart.js