receiving plsql array in javascript

Asked

Viewed 132 times

2

I created a pl cursor, now I’m trying to pass the records to a array javascript to create graphics, the newData will receive the cursor data.

Javascript created is this:

<html>
<head>
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  <script type="text/javascript">
    google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawChart);
    function drawChart() {

     var dataTable = new google.visualization.DataTable();

     var newData = [['Ano', 'Vendas'],
        ['2004',  1000       ],
        ['2005',  1170],
        ['2006',  660],
        ['2007',  1030],
        ['2008',  1530]];


     // determine the number of rows and columns.
      var numRows = newData.length;
      var numCols = newData[0].length;

      // in this case the first column is of type 'string'.
      dataTable.addColumn('string', newData[0][0]);

      // all other columns are of type 'number'.
      for (var i = 1; i < numCols; i++)
        dataTable.addColumn('number', newData[0][i]);           

      // now add the rows.
      for (var i = 1; i < numRows; i++)
        dataTable.addRow(newData[i]);    

    var options = {
      title: 'Vendas anual'
    };

    var chart = new google.visualization.PieChart(document.getElementById('piechart'));

    chart.draw(dataTable, options);
  }
</script>

  • 1

    Okay, buddy, what’s wrong with the code?

  • Are you using any server-side ? PHP, ASP or other ? Request by ajax a page that loads your SP into SQL, return an array in json and take javascript.

  • Thank you, I was able to solve it as follows, quite simply ************* var datatable = new google.visualization.Datatable(); var newData = Array();') FOR rec_data IN cur_data LOOP htp. p('newData.push(["' || rec_dados.retorno || '", ' || rec_dados.registro || ']);') END LOOP;

  • @Mauriciomendes can join an answer here? instead of the comment with the solution...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.