我有这个代码`
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var abc = [
['Language', 'Speakers'],
['German', 5.85],
['French', 1.66],
['Italian', 0.316],
['Romansh', 0.0791]
];
var data = google.visualization.arrayToDataTable(abc);
var options = {
legend: 'none',
pieSliceText: 'label',
title: 'Swiss Language Use (100 degree rotation)',
pieStartAngle: 100,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>`
现在我想从数据库或从服务器端添加动态值这不是问题.. 问题是如何制作&#34; abc&#34;数组动态
提前谢谢
答案 0 :(得分:1)
一个数据结构将使用List<List<string>>
,然后将其序列化。
List<List<string>> lists = new List<List<string>>()
{
new List<string>{"Language", "Speakers"},
new List<string>{"German", "5.85"},
new List<string>{"French", "1.66"},
new List<string>{"Italian", "0.316"},
new List<string>{"Romansh", "0.170"}
};
var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(lists);
输出
[["Language","Speakers"],["German","5.85"],["French","1.66"],["Italian","0.316"],["Romansh","0.170"]]
这将是您查询的起点。
答案 1 :(得分:0)
使用hidden fields
从pageload
var Present = parseInt(document.getElementById('<%= Present.ClientID%>').value);
var absent = parseInt(document.getElementById('<%= Absent.ClientID%>').value);
var NBH = parseInt(document.getElementById('<%= NBH.ClientID%>').value);
var NDS = parseInt(document.getElementById('<%= NDS.ClientID%>').value);
var Delay = parseInt(document.getElementById('<%= Delay.ClientID%>').value);
var Training = parseInt(document.getElementById('<%= Training.ClientID%>').value);
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Present', Present],
['Absent', absent],
['NBH', NBH],
['NDS', NDS],
['Delay', Delay],
['Training', Training]
]);
&#13;
<asp:HiddenField ID="Present" runat="server" />
<asp:HiddenField ID="Absent" runat="server" />
<asp:HiddenField ID="NBH" runat="server" />
<asp:HiddenField ID="NDS" runat="server" />
<asp:HiddenField ID="Delay" runat="server" />
<asp:HiddenField ID="Training" runat="server" />
&#13;