Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to draw a bar chart by passing values from PHP to JavaScript

try { 
$usr = 'MON_DW';
$pswd = '4v$view'; 
$dbConnStr = 'localhost';  
$dbConn = null;
$err = null;
$dbConn = oci_connect($usr,$pswd,$dbConnStr);
$err = oci_error();
$strSQL = "SELECT /*+parallel(B,4)*/ PERCENT_USED FROM (SELECT A.TABLESPACE_NAME,
 ROUND(((A.BYTES-B.BYTES)/A.BYTES)*100,2) PERCENT_USED
FROM
  (SELECT TABLESPACE_NAME,
    SUM(BYTES) BYTES
  FROM DBA_DATA_FILES
  GROUP BY TABLESPACE_NAME
  ) A,
  (SELECT TABLESPACE_NAME,
    SUM(BYTES) BYTES ,
    MAX(BYTES) LARGEST
  FROM DBA_FREE_SPACE
  GROUP BY TABLESPACE_NAME
  ) B
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND ROWNUM< 5
ORDER BY PERCENT_USED DESC)";
$stmt = oci_parse($dbConn,$strSQL);
if ( ! oci_execute($stmt) ){
$err = oci_error($stmt);
trigger_error('Query failed: ' . $err['message'], E_USER_ERROR);
};

$rslt = oci_fetch_array($stmt,OCI_BOTH)      ;
?>
<script>

>  var pausecontent = new Array();

    <?php foreach($rslt as $key => $val){ ?>
        pausecontent.push('<?php echo $val; ?>');    <?php echo $val; } ?>

$(function () {
        $('#container').highcharts({
            chart: {
                type: 'column',
                margin: [ 50, 50, 100, 80]
            },
            title: {
                text: 'World\'s largest cities per 2008'
            },
            xAxis: {
                categories: [
                    'Tokyo',
                    'Jakarta',
                    'New York',
                    'Seoul',
                                                      ],
                labels: {
                    rotation: -45,
                    align: 'right',
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif'
                    }
                }
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Population (millions)'
                }
            },
            legend: {
                enabled: false
            },
            tooltip: {
                pointFormat: 'Tablespaces in EDW : <b>{point.y:.1f} millions</b>',
            },
            series: [{
                name: 'Tablespaces',
                data: pausecontent,
                dataLabels: {
                    enabled: true,
                    rotation: -90,
                    color: '#FF00F',
                    align: 'right',
                    x: 4,
                    y: 10,
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif',
                        textShadow: '0 0 3px black'
                    }
                }
            }]
        });
    });

</script>

<?php     
}


 catch(Exception $exception){
   echo "Exception Details in Accessing find_largeobject details".$exception->getMessage();
        }
share|improve this question

3 Answers 3

you can pase the php array to a json object of javascript like this:

var json = eval(<?php echo json_encode($rslt)?>);
share|improve this answer

Try some thing like this.

<?php
$rslt = array( 
    'Date.UTC(2013, 7, 01)' => 8,
    'Date.UTC(2013, 7, 02)' => 7,
    'Date.UTC(2013, 7, 03)' => 10,
    'Date.UTC(2013, 7, 04)' => 2,       
   );

?>

<script>
//<![CDATA[
var pausecontent = [];

<?php foreach ($rslt as $key => $val) { ?>

pausecontent.push([ <?php echo "'$key', '$val'"; ?>]);

<?php } ?>
//]]>
</script>

After that put the javascript variable on the graph series.

<script>
.
.

 series: [{
            name: 'Tablespaces',
            data: pausecontent,

        }]
 .
 .
</script>
share|improve this answer

Please take look how to parsing data from database http://www.highcharts.com/docs/working-with-data/preprocessing-data-from-a-database, but obviosuly you can also use json_encode($array) and get data by getJSON function in the javascript.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.