bjoost

valueGraph.php

Jun 10th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?php
  2. // This graphs data found in $filename and outputs as a png file.
  3. // Expected format:
  4. // timestamp\tusdSpent\tusdPortfolioValue\n
  5. $filename = "totalUsdLog.txt";
  6.  
  7. require_once 'jpgraph/jpgraph.php';
  8. require_once 'jpgraph/jpgraph_line.php';
  9. require_once 'jpgraph/jpgraph_date.php';
  10. require_once 'jpgraph/jpgraph_scatter.php';
  11.  
  12. $a = preg_split("/\n/", file_get_contents($filename));
  13. $xvalues1 = array();
  14. $yvalues1 = array();
  15. $yvalues2 = array();
  16. foreach ($a as $b) {
  17.     if ($b) {
  18.         $c = preg_split("/\t/", $b);
  19.         $xvalues1[] = (float)$c[0];
  20.         $yvalues1[] = (float)$c[1];
  21.         $yvalues2[] = (float)$c[2];
  22.         $yvalues3[] = (float)($c[2] - $c[1]);
  23.     }
  24. }
  25.  
  26. $graph = new Graph(750,400);
  27. $graph->SetScale("datlin");
  28.  
  29. $graph->xaxis->scale->SetTimeAlign( DAYADJ_1 );
  30. $graph->xaxis->SetTextTickInterval(3600*24*7);
  31. $graph->xaxis->SetTextLabelInterval(7);
  32.  
  33. $graph->yaxis->SetTitle("USD");
  34. //$graph->yaxis->SetLabelMargin(15);
  35.  
  36. //$graph->img->SetMargin(40,40,40,40);     
  37.  
  38. $graph->title->Set("Cryptocurrency portfolio value");
  39. $graph->title->SetFont(FF_FONT1,FS_BOLD);
  40.  
  41. // waarde
  42. $sp1 = new ScatterPlot($yvalues2,$xvalues1);
  43. $sp1->mark->SetWidth(2);
  44.  
  45. // inleg
  46. $sp2 = new ScatterPlot($yvalues1,$xvalues1);
  47. $sp2->mark->SetFillColor("red");
  48. $sp2->mark->SetWidth(2);
  49.  
  50. // winst/verlies
  51. $sp3 = new ScatterPlot($yvalues3,$xvalues1);
  52. $sp3->mark->SetFillColor("green");
  53.  
  54.  
  55. $graph->Add($sp1);
  56. $graph->Add($sp2);
  57. $graph->Add($sp3);
  58. $graph->Stroke();
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment