2013-07-04 34 views
1

我以前使用highcharts從數據庫中獲取數據,但是因爲它位於更新面板中,所以沒有顯示數據。使用這種無線電使用單選按鈕,highcharts從服務器獲取數據

<input class="test" name="ga" type="radio" value="a"> name</input> 
<input class="test" name="ga" type="radio" value="b"> last</input> 
<input class="test" name="ga" type="radio" value="c"> first</input> 

,數據是工作,因爲我稱爲從vb.net我通過使隱藏字段,並得到數據集到一個數組這樣做的背面代碼的JavaScript,從那裏我使用的Json然後將其稱爲隱藏值並將其顯示在圖表上。但是現在我需要使用單選按鈕來實現聊天:下面的代碼是我的單選按鈕,同樣的概念...

<asp:RadioButtonList RepeatDirection="Horizontal" CssClass="radioList test" 
        ID="RadioButtonList1" AutoPostBack="true" runat="server" 
        RepeatLayout="Flow" name="ga" type="radio"> 
    <asp:ListItem Selected="True" Value="a">name</asp:ListItem> 
    <asp:ListItem Value="a">first</asp:ListItem> 
    <asp:ListItem Value="a">last</asp:ListItem> 
</asp:RadioButtonList> 

當我使用此代碼,數據確實不知道,當我刷新它不從服務器獲取數據。我的JavaScript代碼:

$(function() { 
var chart = new Highcharts.Chart({ 
    chart: { 
     renderTo: 'container' 
    } 
}); 

$(".test").change(function() { 
    var value = this.getAttribute("value"); 
    while (chart.series.length > 0) { 
     chart.series[0].remove(true); 
    } 
    if (value == 'a') { 
     chart.xAxis[0].update({categories: ['Jan', 'Feb', 'Mar']}); 
     chart.yAxis[0].setTitle({ text: "name" }); 

     chart.addSeries({ 
      name: 'Rainfall11', 
      type: 'column', 
      data:array(comes from vb.net)  
     });  
     chart.addSeries({ 
      name: 'Rainfall2', 
      type: 'column', 
      data: array2 (comes from vb.net)    
     });      
     chart.addSeries({ 
      name: 'Rainfall3', 
      type: 'column', 
      color: '#FFA500', 
      data: array3 (comes from vb.net)    
     }); 
    } else if (value == 'b') { 

     chart.yAxis[0].setTitle({ text: "first" }); 
    } else if (value == 'c') { 
      chart.addSeries({ 
      name: 'Rainfall5', 
      type: 'column', 
      data:array5   
     }); 
     chart.addSeries({ 
      name: 'Rainfall6', 
      type: 'column', 
      data:array6 
     }); 
    } else { 
     alert("Error!");  
    } 
});}); 

的問題是,我無法從服務器獲取數據,因爲當我刷新頁面它不加載它,它只調用它的JavaScript ..我有谷歌這一點,覺得它與更新面板,使用重繪方法或使用RegisterClientScriptBlock有關。

這是我從MSDN了,爲的RegisterClientScriptBlock:

Dim script As String 
    script = _ 
    "function ToggleItem(id)" & _ 
    " {" & _ 
    " var elem = $get('div'+id);" & _ 
    " if (elem)" & _ 
    " {" & _ 
    "  if (elem.style.display != 'block') " & _ 
    "  {" & _ 
    "  elem.style.display = 'block';" & _ 
    "  elem.style.visibility = 'visible';" & _ 
    "  } " & _ 
    "  else" & _ 
    "  {" & _ 
    "  elem.style.display = 'none';" & _ 
    "  elem.style.visibility = 'hidden';" & _ 
    "  }" & _ 
    " }" & _ 
    " }" 

    ScriptManager.RegisterClientScriptBlock(_ 
     Me, _ 
     GetType(Page), _ 
     "ToggleScript", _ 
     script, _ 
     True) 

所以我的javascript代碼往裏走呢?

回答

0

您可以在change處理程序內執行一次AJAX調用(例如,使用jQuery的get,因爲它似乎是您正在使用的)以獲取必要的數據。服務器端,您將返回JSON與數組或數組,並根據需要分配它/他們。既然你使用VB.NET,我猜你正在使用ASP.NET,所以檢查他們的文檔。

+0

我被告知,使用vb中的RegisterClientScriptBlock方法將工作。然後使用highchrts重繪,但改變了javascript的功能,但問題在於它將被排除 – al123

+0

我從來沒有使用過AJAX調用,但我被告知它可以與RegisterClientScriptBlock – al123

+0

工作我從來沒有使用RegisterClientScriptBlock,所以我不能幫你。如果發現[this](http://encosia.com/jquery-for-the-asp-net-developer/)系列帖子在過去很有用(我已轉移到ASP.NET MVC)。 – ssarabando

0

首先,嘗試將您的JavaScript代碼放入function pageLoad(sender, args) {}。這將確保在部分回發完成時運行JavaScript代碼。

接下來,你的RadioButtonList裏面的UpdatePanel?如果不是,則將AutoPostBack設爲False,並將其指定爲UpdatePanel的觸發器。

+0

在vb代碼中調用它?並且不,但是,更新面板中包含高圖容器div。看看我的eddited帖子 – al123

+0

我的意思是說你已經把你的客戶端代碼放在jQuery document.ready中,它的簡寫形式是$(function(){})()'。相反,把它放在'function pageLoad(sender,args){}'裏面。這樣您的客戶端代碼將在每次回發時執行。我不是在談論'RegisterClientScriptBlock'(用於從代碼隱藏中推送javascript)。另外,你是否添加了你的radiobuttonlist作爲updatepanel的觸發器? – Abhitalks