我正在尝试将我的代码集成到 Google Chart API。我想从后面的代码中手动设置谷歌图表标题和轴列名称。我尝试了下面的代码,但不起作用。有什么建议么?
ASPX 文件
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { "packages": ["corechart"] });
function drawProgrammingChart() {
var data = new google.visualization.DataTable(operationdetails, 0.5);
var chart = new google.visualization.LineChart(document.getElementById("divprog"));
**var xAxis = document.getElementById("txtXAxisName");**
**console.log(xAxis);**
var yAxis = document.getElementById("txtYAxisName");
chart.draw(data, {
title: "Visualization Satisfaction", hAxis: { title: "Programming method" }, vAxis: { title: "Units" }
});
}
google.setOnLoadCallback(drawProgrammingChart);
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id="divprog" style="width: 750px; height: 350px;">
</div>
<asp:HiddenField ID="txtXAxisName" runat="server" />
<asp:HiddenField ID="txtYAxisName" runat="server" />
</asp:Content>
在后面的代码中,我想手动设置隐藏字段值。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = generateDataTable();
**txtXAxisName.Value = "Days";**
txtYAxisName.Value = "Duration";
LoadChart(dt, "operationdetails");
}
}
private void LoadChart(DataTable table, string jsName)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(),
jsName, string.Format("var {0} = {1};", jsName, new Bortosky.Google.Visualization.GoogleDataTable(table).GetJson()), true);
}
获取元素 txtAxisName 时,它为空。