使用单选按钮,highcharts,vb.net从服务器获取数据

时间:2013-07-04 10:42:03

标签: javascript asp.net .net vb.net 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代码也在里面吗?

2 个答案:

答案 0 :(得分:0)

您可以在change处理程序中进行一次AJAX调用(使用jQuery的get,例如您正在使用它)以获取必要的数据。在服务器端,您将返回带有数组或数组的JSON,并根据需要分配它们。由于您使用的是VB.NET,我猜您正在使用ASP.NET,因此请查看其文档。

答案 1 :(得分:0)

首先,尝试将您的javascript代码放在function pageLoad(sender, args) {}中。这将确保在部分回发完成时运行javascript代码。

接下来,您的RadioButtonList是否在UpdatePanel中?如果没有,则将AutoPostBack设置为False并将其指定为UpdatePanel的触发器。