我在Session [“PnlDataForChart”]中有一个适当格式化字符串的字符串[]
但我无法在Dygraph中显示它们。我试图检查dataArray,但是在VS调试器中看不到它,并且我不确定如何在Firebug中执行它。
这是否为Dygraph正确设置?
来自页面来源:
var dataArray = [];
<div>
dataArray.push("Date,Pnl");
</div>
<div>
dataArray.push("2016/11/01 01:01,0.0000");
</div>
<div>
dataArray.push("2016/11/01 01:02,0.0000");
</div>
<div>
dataArray.push("2016/11/01 01:03,0.0000");
</div>
<div>
dataArray.push("2016/11/01 01:04,0.0000");
</div>
<div>
dataArray.push("2016/11/01 01:05,0.0000");
</div>
<div>
dataArray.push("2016/11/01 01:06,0.0000");
</div>
从查看页面:
<div id="ExportDiv">
<script type="text/javascript"
src="dygraph-combined-dev.js"></script>
<div id="graphdiv"></div>
</script>
<script type="text/javascript">
var dataArray = [];
@{
foreach (var line in (string[])Session["PnlDataForChart"])
{
<div>
dataArray.push("@line");
</div>
}
}
g = new Dygraph(
document.getElementById("graphdiv"),
dataArray
);
</script>
</div>
答案 0 :(得分:1)
你的代码中有很多混乱。只是一些错误:
<div id="graphdiv"></div>
</script>
之后,您有<script></script>
这是不必要的。<div></div>
阻止状态,因此无法放置@:dataArray.push("@line");
。在脚本块中,您只能使用JavaScript语法!var dataArray = new string[] {
"Date,Temperature",
"2008-05-07,75",
"2008-05-08,70",
"2008-05-09,80"
};
Session["PnlDataForChart"] = dataArray;
这就是整个解决方案的样子:
控制器:
<script src="~/Scripts/dygraph.js"></script>
<div id="ExportDiv">
<div id="graphdiv"></div>
</div>
<script type="text/javascript">
var dataArray = [];
@{
foreach (var line in (string[])Session["PnlDataForChart"])
{
@:dataArray.push("@line");
}
}
g = new Dygraph(document.getElementById("graphdiv"), dataArray.join('\n'));
</script>
并查看:
frmDashboardJBCreate