感谢您到目前为止的所有帮助,我已经进行了以下更改
这是运行时的代码:
<body>
<form method="post" action="ResultsDetails.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzQ5NzY1NjU0ZGRuWExqnYyaWn0sRggTtOIdHlawc3aZvdNLKpOq0D+uMQ==" />
</div>
<div id="placeholder" style="width:600px;height:300px;"></div>
<script type="text/javascript">
//<![CDATA[
var arrayOfResults = new Array();
arrayOfResults[0] = 2;
arrayOfResults[1] = 4;
arrayOfResults[2] = 5;
arrayOfResults[3] = 1;
arrayOfResults[4] = 4;
var numberArray = Array(1, 2, 3, 4, 5);
//]]>
</script>
</form>
<div id="codeGeneration">
<script type="text/javascript">
$(document).ready(function () {
$.plot($('#placeholder'), [arrayOfResults, numberArray]);
});
</script>
</div>
</body>
绘图方法正在运行,但我不断收到错误说数组尚未初始化?
我在用着
ClientScript.RegisterStartupScript(this.GetType(), "run", sb.ToString() ,true);
编写数组代码。
Sloved 我做了以下
private void generateJScriptArray(int[] array)
{
StringBuilder sb = new StringBuilder();
sb.Append("var arrayOfResults = Array(); \n ");
for (int i = 0; i < array.Length; i++)
{
sb.Append("arrayOfResults[" + i + "] = " + array[i] + "; \n ");
}
sb.Append("var numberArray = Array(1, 2, 3, 4, 5); \n");
sb.Append("alert(numberArray[0]); \n");
sb.Append("$(document).ready(function () { \n $.plot($('#placeholder'), [arrayOfResults, numberArray]); \n });");
ClientScript.RegisterStartupScript(this.GetType(), "run", sb.ToString() ,true);
}
感谢所有帮助过的人。