gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 09:03:01 24 4
gpt4 key购买 nike

我之前使用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>

使用这个 radio ,数据正在工作,因为我从 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 代码在里面吗?

最佳答案

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

关于javascript - 使用单选按钮、highcharts、vb.net 从服务器获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17468217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com