protected function StatisticsPageTrait::buildDonutChart in Opigno statistics 3.x
Prepare the settings array to build the donut chart.
Parameters
float $value: The value of the statistics parameter.
string $id: The canvas element ID to display the chart in.
Return value
array Settings array to build the donut chart.
2 calls to StatisticsPageTrait::buildDonutChart()
- DashboardForm::buildTrainingsProgress in src/
Form/ DashboardForm.php - Builds trainings progress.
- TrainingForm::buildTrainingsProgress in src/
Form/ TrainingForm.php - Builds training progress.
File
- src/
StatisticsPageTrait.php, line 113
Class
- StatisticsPageTrait
- Common helper methods for a statistics pages.
Namespace
Drupal\opigno_statisticsCode
protected function buildDonutChart(float $value, string $id) : array {
$percent = round(100 * $value);
// Get color palette.
$theme = \Drupal::theme()
->getActiveTheme()
->getName();
$color_palette = color_get_palette($theme);
$color = $color_palette['desktop_link'] ?? '#4ad3b0';
return [
'id' => $id,
'type' => 'doughnut',
'datasets' => [
[
'data' => [
$percent,
100 - $percent,
],
'backgroundColor' => [
$color,
'#d5d5d5',
],
'hoverBackgroundColor' => [
$color,
'#d5d5d5',
],
'borderWidth' => 0,
],
],
'options' => [
'aspectRatio' => 1,
'cutout' => '85%',
'elements' => [
'arc' => [
'roundedCornersFor' => 0,
],
'center' => [
'text' => "{$percent}%",
'fontColor' => '#2F3758',
'fontStyle' => '800',
'fontFamily' => 'Montserrat,Geneva,Arial,Helvetica,sans-serif',
'minFontSize' => 16,
'maxFontSize' => 43,
'lineHeight' => 30,
],
],
],
];
}