Advertisement
Lonster_Monster

Gaph#1.php

Aug 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. $dataPoints = array();
  3. //Best practice is to create a separate file for handling connection to database
  4. try{
  5. // Creating a new connection.
  6. // Replace your-hostname, your-db, your-username, your-password according to your database
  7. $link = new \PDO( 'mysql:host=localhost;dbname=users;charset=utf8mb4', //'mysql:host=localhost;dbname=canvasjs_db;charset=utf8mb4',
  8. 'root', //'root',
  9. '', //'',
  10. array(
  11. \PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  12. \PDO::ATTR_PERSISTENT => false
  13. )
  14. );
  15.  
  16. $handle = $link->prepare('select Date, Profits from bot_items_db');
  17.  
  18. $handle->execute();
  19. $result = $handle->fetchAll(\PDO::FETCH_OBJ);
  20.  
  21. foreach($result as $row){
  22. array_push($dataPoints, array("x"=> $PHPstr=strtotime($row->Date)*1000, "y"=> $row->Profits));
  23. }
  24. $link = null;
  25. }
  26. catch(\PDOException $ex){
  27. print($ex->getMessage());
  28. }
  29.  
  30. ?>
  31.  
  32. <!DOCTYPE HTML>
  33. <html>
  34. <head>
  35. <script>
  36. window.onload = function () {
  37.  
  38. var chart = new CanvasJS.Chart("chartContainer", {
  39. animationEnabled: true,
  40. title:{
  41. text: "Bot(s) Profits by Year"
  42. },
  43. axisY: {
  44. title: "Profits in USD",
  45. valueFormatString: "#0,,.",
  46. suffix: "00",
  47. prefix: "$"
  48. },
  49. data: [{
  50. type: "spline",
  51. markerSize: 5,
  52.  
  53. xValueFormatString: "YYYY",
  54. yValueFormatString: "$#,##0.##",
  55. xValueType: "dateTime",
  56. dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
  57. }]
  58. });
  59.  
  60. chart.render();
  61.  
  62. }
  63. </script>
  64. </head>
  65. <body>
  66. <div id="chartContainer" style="height: 370px; width: 100%;"></div>
  67. <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement