<?php
/**
 * @version        1.9.7
 * @package        Joomla
 * @subpackage     EDocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2024 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */
defined('_JEXEC') or die('');
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;

?>
<table class="table dashboard-table" style="width:100%;">
	<tbody>
	<tr>
		<td style="width:100%;">
			 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
			 <canvas id="myChart" style="width:100%; height:400px;"></canvas>
			 <script type="text/javascript">
				jQuery(document).ready(function () {
					showGraph(0);
				});

				function showGraph(range_option)
				{
					{
						jQuery.post("<?php echo Uri::root().'administrator/index.php?option=com_edocman&task=downloadtrend&tmpl=component&format=json'; ?>&range_option=" + range_option,
						function (data)
						{
							data = JSON.parse(data);
							var name = [];
							var ndownloads = [];
							console.log(data);


							for (var i in data) {
								name.push(data[i].month);
								ndownloads.push(data[i].ndownloads);
							}

							var chartdata = {
								labels: name,
								datasets: [
									{
										label: '<?php echo Text::_("EDOCMAN_NUMBER_DOWNLOADS");?>',
										borderColor: '#46d5f1',
										data: ndownloads,
										fill: false
									}
								]
							};

							var graphTarget = jQuery("#myChart");

							var barGraph = new Chart(graphTarget, {
								type: 'line',
								data: chartdata
							});
						});
					}
				}
			 </script>
			 <strong>
				<?php echo Text::_('EDOCMAN_INITIAL_RANGE');?>: <?php echo $this->lists['initial_range'];?>
			 </strong>
			</td>
		</tr>
	</tbody>
</table>
