You are here

public function UserStatisticsManager::buildBarChart in Opigno statistics 3.x

Prepare the array of settings to build the bar chart.

Parameters

array $data: The chart data.

string $canvas_id: The ID of the html canvas element to render the chart in.

Return value

array The array of settings to build the bar chart.

1 call to UserStatisticsManager::buildBarChart()
UserStatisticsManager::renderUserTrainingsCharts in src/Services/UserStatisticsManager.php
Prepare the render array to display the user training charts.

File

src/Services/UserStatisticsManager.php, line 503

Class

UserStatisticsManager
User statistics manager service definition.

Namespace

Drupal\opigno_statistics\Services

Code

public function buildBarChart(array $data, string $canvas_id) {

  //$bar_color = '#4AD3B0';

  // Get color palette.
  $theme = \Drupal::theme()
    ->getActiveTheme()
    ->getName();
  $color_palette = color_get_palette($theme);
  $bar_color = $color_palette['desktop_link'] ?? '#4AD3B0';
  return [
    'id' => $canvas_id,
    'type' => 'bar',
    'labels' => array_keys($data),
    'datasets' => [
      [
        'data' => array_values($data),
        'barThickness' => 15,
        'backgroundColor' => $bar_color,
        'hoverBackgroundColor' => $bar_color,
        'borderColor' => $bar_color,
        'borderWidth' => 2,
        'borderRadius' => 20,
        'borderSkipped' => FALSE,
      ],
    ],
    'options' => [
      'scales' => [
        'yAxes' => [
          'beginAtZero' => TRUE,
          'ticks' => [
            'precision' => 0,
          ],
        ],
      ],
    ],
  ];
}