SHARE
TWEET

Untitled

a guest Jan 11th, 2019 192 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. date_default_timezone_set('Europe/Warsaw');
  4.  
  5. function wykres($db, $table, $description, $rgbcolor)
  6. {
  7.         echo "<canvas id=\"".$table."\"></canvas>";
  8.  
  9.         $labels = "";
  10.         $data = "";
  11.         $query = mysqli_query($db, "SELECT * FROM ( SELECT id, data, value FROM `".$table."` ORDER BY id DESC LIMIT 60 ) sub ORDER BY id ASC");
  12.         while ($row = mysqli_fetch_array($query)) {
  13.         $labels .= "\"".date('G:i d-m', $row{'data'})."\",";
  14.         $data .= "".$row{'value'}.",";
  15.         }
  16.  
  17.  
  18.         echo "<script>
  19. var ctx = document.getElementById('".$table."').getContext('2d');
  20. var chart = new Chart(ctx, {
  21.    // The type of chart we want to create
  22.    type: 'line',
  23.  
  24.    // The data for our dataset
  25.    data: {
  26.        labels: [".$labels."],
  27.        datasets: [{
  28.            label: \"".$description."\",
  29.            backgroundColor: 'rgb(".$rgbcolor.")',
  30.            borderColor: 'rgb(".$rgbcolor.")',
  31.            data: [".$data."],
  32.            fill: false,
  33.        }]
  34.    },
  35.  
  36.    // Configuration options go here
  37.    options: {}
  38. });
  39. </script>";
  40. }
  41. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top