Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php
  2.    
  3. // content="text/plain; charset=utf-8"
  4. require_once ('jpgraph/src/jpgraph.php');
  5. require_once ('jpgraph/src/jpgraph_line.php');
  6. require_once ('jpgraph/src/jpgraph_scatter.php');
  7.  
  8. //data goes here
  9. $datay1 = array(15,21,24,10,37,29,47);
  10.  
  11. // Setup the graph
  12. $graph = new Graph(1000,800);
  13.  
  14. $graph->SetScale("textlin",0,50);
  15.  
  16. $graph->title->Set("Military Expendture (% GDP)");
  17.  
  18. $graph->SetBox(false);
  19. $graph->yaxis->HideLine(false);
  20. $graph->yaxis->HideTicks(false,false);
  21. $graph->yaxis->HideZeroLabel();
  22.  
  23. //get data for x axis
  24. function xaxislabels()
  25. {
  26.     //variables
  27.     $serveraddress = "r76frpf2a1.database.windows.net,1433";
  28.     $servername = "militaryexpenditure";
  29.     $username = "militaryexpenditure";
  30.     $password = "Cosmocat17";
  31.  
  32.     $conn = new PDO ("sqlsrv:server = $serveraddress; Database = $servername", $username, $password);
  33.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  34.  
  35.     $data = $conn->prepare("SELECT [Country Name] FROM Expenditure");
  36.     $data->execute();
  37.  
  38.     $countrydata = array();
  39.     $i = 0;
  40.  
  41.     while($column = $data->fetch(PDO::FETCH_ASSOC))
  42.     {
  43.         $countrydata[$i++] = $column;
  44.     }
  45.  
  46.     $graph->xaxis->SetTickLabels->(array($countrydata);
  47. }
  48.  
  49. //labelling axis
  50. xaxislabels();
  51.  
  52. //creating the plot
  53. $p1 = new LinePlot($datay1);
  54. $graph->Add($p1);
  55.  
  56. //image for markers
  57. $p1->mark->SetType(MARK_IMG,'sunflower.gif',1.0);
  58. $p1->SetLegend('pew');
  59. $p1->SetColor('#CD5C5C');
  60.  
  61. $graph->Stroke();
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement