defined('_JEXEC') or die; /* @type \Joomla\Registry\Registry $params */ /* @type array $chartData */ /* @type object $module */ // Require our Chart.js source JHtml::_('script', 'mod_joomladata/Chart.js', false, true); // Figure out what type of chart we're building $chartType = $params->get('chartType', 'Doughnut'); // Set the container ID using the module's ID for unique instances $containerId = 'joomlaChart-' . $module->id; $dataRows = ''; $iteration = 1; // Get our helper so we can generate colors $helper = new JoomlaStatChartsHelper(); foreach ($chartData as $row) { $dataRows .= '{value: ' . $row['count'] . ', label: "' . $row['name'] . '", color: "' . $helper->getColor() . '"}'; if ($iteration != count($chartData)) { $dataRows .= ','; } $iteration++; } ?> <canvas id="<?php echo $containerId; ?> " width="<?php echo $params->get('containerWidth', 400); ?> " height="<?php echo $params->get('containerHeight', 400);
* @var array $chartData The data to be rendered in the chart */ // Require our Chart.js source JHtml::_('script', 'mod_joomladata/Chart.js', false, true); // Figure out what type of chart we're building $chartType = $params->get('chartType', 'Doughnut'); // Set the container ID using the module's ID for unique instances $containerId = 'joomlaChart-' . $module->id; $labels = []; $dataObject = (object) ['data' => [], 'backgroundColor' => []]; // Get our helper so we can generate colors $helper = new JoomlaStatChartsHelper(); foreach ($chartData as $row) { $labels[] = $row['name']; $dataObject->data[] = $row['count']; $dataObject->backgroundColor[] = $helper->getColor(); } $data = ['labels' => $labels, 'datasets' => [$dataObject]]; ?> <canvas id="<?php echo $containerId; ?> " width="100" height="100"></canvas> <script type="text/javascript"> var <?php echo "ctx{$module->id}"; ?> = document.getElementById('<?php echo $containerId;