Sebuahhobi98

charts.js

Apr 9th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8" />
  6. <title>Arduino Web Server</title>
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8.  
  9. <link rel="stylesheet" href="<?php echo base_url();?>/assets/css/bootstrap.min.css">
  10. </head>
  11. <body>
  12. <div class="chart-container" style="position: relative; height:40vh; width:80vw">
  13. <canvas id="mychart"></canvas>
  14. </div>
  15. <script src="<?php echo base_url();?>/assets/jquery.min.js"></script>
  16. <script src="<?php echo base_url();?>/assets/js/bootstrap.min.js"></script>
  17. <script src="<?php echo base_url();?>/assets/charts/Chart.min.js"></script>
  18. <script>
  19. var isActive = true;
  20.  
  21. $().ready(function () {
  22. //EITHER USE A GLOBAL VAR OR PLACE VAR IN HIDDEN FIELD
  23. //IF FOR WHATEVER REASON YOU WANT TO STOP POLLING
  24. pollServer();
  25. });
  26.  
  27. function pollServer()
  28. {
  29. if (isActive)
  30. {
  31. window.setTimeout(function () {
  32. $.ajax({
  33. url : "<?php echo base_url();?>charts/index",
  34. cache : false,
  35. dataType : 'json',
  36. type : "POST",
  37. success: function (result) {
  38. //SUCCESS LOGIC
  39. var data = Array();
  40. var waktu = Array();
  41. data = result.data;
  42. waktu = result.waktu;
  43. console.log(waktu);
  44. var ctx = $("#mychart");//document.getElementById('mychart').getContext('2d');
  45. var chart = new Chart(ctx, {
  46. type: 'line',
  47.  
  48. // The data for our dataset
  49. data: {
  50. //labels: ["Januari", "Februari", "Maret", "April", "Mei", "June", "July", "Agustus", "September", "OKtober", "November", "Desember"],
  51. labels: waktu,
  52. datasets: [
  53. {
  54. label: "Data Penjualan",
  55. backgroundColor: 'rgb(0, 0, 255)',
  56. borderColor: 'rgb(0, 0, 255)',
  57. //data: [10000,50000,1000,6000,0,90,100,1000,9999,1000,0,2],
  58. data: data,
  59. }
  60. ]
  61. },
  62.  
  63. // Configuration options go here
  64. options: {
  65. scales: {
  66. yAxes: [{
  67. ticks: {
  68. beginAtZero:true
  69. }
  70. }]
  71. }
  72. }
  73. });/**/
  74. pollServer();
  75. },
  76. error: function () {
  77. //ERROR HANDLING
  78. pollServer();
  79. }});/**/
  80. }, 3000);//2,5 detik
  81. }
  82. }
  83. </script>
  84. </body>
  85. </html>
Add Comment
Please, Sign In to add comment