I am working on a query that give me a view of the last 12 months, group by affiliate_id using canvasjs.
I need to show a X axis (LAST 12 months) and Y axis (number of cliks with the same id_aff) `
Here is my current query looks like :
SELECT COUNT(*) AS value FROM affiliation_clicks GROUP BY MONTH(FROM_UNIXTIME(date(timestamp)), YEAR(FROM_UNIXTIME(date(timestamp))
Here is my current code :
<?php include("config.php"); $dataPoints = array(); $query = mysqli_query($bdd, "SELECT COUNT(*) AS value FROM affiliation_clicks GROUP BY MONTH(FROM_UNIXTIME(date(timestamp)), YEAR(FROM_UNIXTIME(date(timestamp))"); while($row = mysqli_fetch_array($query { $dataPoints[] = array("value" => $row['value'], "label" => $row['date(timestamp)']); } ?> <!DOCTYPE HTML> <html> <head> <script> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { title: { text: "Number of visits per month" }, axisY: { title: "Number of Clicks" }, data: [{ type: "line", dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?> }] }); chart.render(); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script> </body> </html>
Best regards
https://stackoverflow.com/questions/67444517/php-mysql-with-chartjs-count-click-per-month May 08, 2021 at 01:56PM
没有评论:
发表评论