user5149297
user5149297

Reputation:

create chart with oracle query

i am trying to create a chart pie with a query from oracle database. i have already connect to the data base and echo the results,but i cant create a chart.any suggestion about this?

<?php
$tns = "  
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxxx.xxx.xxx)(PORT = xxxx))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = XE)
    )
  )
       ";
$db_username = "xxx";
$db_password = "xxxxR";
try{
    $conn = new PDO("oci:xxxx=".$tns,$db_username,$db_password);
}catch(PDOException $e){
    echo ($e->getMessage());
}
if (!$conn) {
   $m = oci_error();
   echo $m['message'], "\n";
   exit;
}
else {
   echo "Connected to Oracle!";
}
 
$query = "SELECT T71.C_C1003000015, COUNT (T71.C1)
  FROM ICT_DATABASE.T71 T71
WHERE (T71.C_C1003000015 NOT IN (exelllllllllxx.xxxx.xxx'))
       AND trunc(T71.ARRIVAL_DATE) = trunc(sysdate)
GROUP BY T71.C_C1003000015";
 
$stmt = $conn->prepare($query);
 
if ($stmt->execute()) {
    echo "<h4>$query</h4>";
    echo "<pre>";
    while ($row = $stmt->fetch()) {
        print_r($row);
    }
    echo "</pre>";
	}
	
	
?>

that code is working and export data how can i create a chart now?

Upvotes: 0

Views: 307

Answers (1)

WhiteHat
WhiteHat

Reputation: 61222

ok, here goes.

you need to add Google's scripts to your page.

<script src="https://www.google.com/jsapi"></script>

Add this div where you want the chart...

<div id="piechart" style="width: 900px; height: 500px;"></div>

then add this JavaScript, assuming you leave the output in the <pre> element

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);

function drawChart() {
  var googleArray = [];
  googleArray.push(['Department', 'Value']);
  var testRow = document.getElementsByTagName('PRE')[0].innerHTML;
  var testArr = testRow.split('IT-EXT-COSMOTE-');
  var deptSplit;

  for (var i = 0; i < testArr.length; i++) {
    if (testArr[i] !== '') {
      deptSplit = testArr[i].split(' - ');
      googleArray.push([deptSplit[0], Number(deptSplit[1])]);
    }
  }

  var dataTable = new google.visualization.arrayToDataTable(googleArray, false);
  var chartOptions = {title: 'Department Totals'};
  var chart = new google.visualization.PieChart(document.getElementById('piechart'));
  chart.draw(dataTable, chartOptions);
}

let me know if you need further help...

Upvotes: 1

Related Questions