Advertisement
Guest User

jpgraph demo

a guest
Aug 31st, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php // content="text/plain; charset=utf-8"
  2. require_once ('jpgraph/jpgraph.php');
  3. require_once ('jpgraph/jpgraph_line.php');
  4.  
  5. function scaleNumber($val, $in_min, $in_max, $out_min, $out_max) {
  6.   return intval(($val - $in_min) * ($out_max - $out_min) / ($in_max - $in_min) + $out_min);
  7. }
  8.  
  9. $l1datay = [];
  10. $datax = [];
  11. $maxData = 266;
  12.  
  13. for($i = 0; $i <= $maxData; ++$i) {
  14.   // demodaten erzeugen
  15.   $l1datay[] = $i % 35 == 0 ? rand(0, 200) : rand(10,100);
  16.   // label erzeugen und auf interval [0,25] runterrechnen.
  17.   $datax[] = scaleNumber($i, 0, $maxData, 0, 24);
  18. }
  19. $l1datay[$maxData] = 200; // letzten Datenpunkt als Ausreißer um zu sehen ob er noch im Bild ist
  20.  
  21. // Create the graph.
  22. $graph = new Graph(800,400);
  23. $graph->clearTheme();
  24. $graph->SetScale("textlin");
  25.  
  26. // Label nur alle /24 anzeigen
  27. $graph->xaxis->SetTextLabelInterval(266/24);
  28. // Label array setzen
  29. $graph->xaxis->SetTickLabels($datax);
  30.  
  31. // Create the linear error plot
  32. $l1plot=new LinePlot($l1datay);
  33. $l1plot->SetColor("red");
  34. $l1plot->SetWeight(2);
  35. $l1plot->SetLegend("Prediction");
  36.  
  37. //Center the line plot in the center of the bars
  38. $l1plot->SetBarCenter();
  39.  
  40. // Add the plots to t'he graph
  41. $graph->Add($l1plot);
  42.  
  43. $graph->title->Set("Linie");
  44. $graph->xaxis->title->Set("X-title");
  45. $graph->yaxis->title->Set("Y-title");
  46.  
  47. $graph->title->SetFont(FF_FONT1,FS_BOLD);
  48. $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
  49. $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
  50.  
  51. // Display the graph
  52. $graph->Stroke();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement