2012-12-04 82 views
0

我在線圖中使用google-api。在jsp頁面中,我以這種方式實現:但無法獲取值,我的查詢做得很好但無法運行在動態,居然請點擊此鏈接:enter link description here無法在折線圖中動態顯示數據

<script type="text/javascript" src="https://www.google.com/jsapi"></script> 
<script type="text/javascript"> 
<% 
Connection con = null; 
Statement stmt = null; 

con = LoginDB.createConnection(); 
stmt = con.createStatement(); 
String sql="select Day(date) as regDate,count(name) as NoOfReg from info where DATE(date) > DATE_SUB(curdate(),interval 365 day)group by regDate order by date asc;"; 
ResultSet rs = stmt.executeQuery(sql); 
%> 

<% while(rs.next()){ %> 
<script type="text/javascript"> 
google.load("visualization", "1", {packages:["corechart"]}); 
google.setOnLoadCallback(drawChart); 
function drawChart() { 
    var data = google.visualization.arrayToDataTable([ 
    ['regDate', 'Registration'], 
    ['<%= rs.getString(1)%>', <%= rs.getString(2)%>] 
    ]); 

    var options = { 
    title: 'No of Registration per Day' 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
} 
</script> 

任何輸入將不勝感激。

回答

0

試試這個

<script type="text/javascript"> 
      var data = ""; 
      <% while(rs.next()){ %> 
        data += ""+['<%= rs.getString(1)%>', <%= rs.getString(2)%>]+"," 
      <% } %> 
    </script> 

    <script type="text/javascript"> 
      google.load("visualization", "1", {packages:["corechart"]}); 
      google.setOnLoadCallback(drawChart); 
      function drawChart() { 
        var data = google.visualization.arrayToDataTable([ 
             ['regDate', 'Registration'], 
             data 
           ]); 

        var options = { 
          title: 'No of Registration per Day' 
          }; 

        var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
        chart.draw(data, options); 
      } 
    </script> 
+0

..它不工作 – user1645434