从javascript加载asp:chart
以下逻辑在网页加载时运行,并调用局部视图以在图表中显示数据:从javascript加载asp:chart,javascript,c#,asp.net-mvc,Javascript,C#,Asp.net Mvc,以下逻辑在网页加载时运行,并调用局部视图以在图表中显示数据: <img src='@Url.Action("_GetChartDetails", "Chart", new { chartType = "Won" })' id="chartid" /> 检查图像定义是否正确: .success(function (response) { var image = document.createElement('img'); image.onload = function () {
<img src='@Url.Action("_GetChartDetails", "Chart", new { chartType = "Won" })' id="chartid" />
检查图像定义是否正确:
.success(function (response) {
var image = document.createElement('img');
image.onload = function () {
//if it's correct created you can open it in console (click)and see what your server returns, it may be the correct response but you may have issues with CSS.
console.log(image);
};
image.src = response;
}
控制台可单击图像:
不要手动执行
$http.get
生成图表,为什么不将图像源更改为指向局部视图并传递所需参数(赢或输):
浏览器控制台中有错误吗?没有,但这没有意义,因为MVC控制器是从上面的javascript调用的。我不确定javascript是否将响应数据类型转换为
.success(function (response) {
var image = document.createElement('img');
image.onload = function () {
//if it's correct created you can open it in console (click)and see what your server returns, it may be the correct response but you may have issues with CSS.
console.log(image);
};
image.src = response;
}
$scope.GetChartDetails = function (chartType) {
var img = document.createElement('img');
img.src = "/Chart/_GetChartDetails?chartType=" + chartType;
var node = document.getElementById('chart');
while (node.hasChildNodes()) {
node.removeChild(node.lastChild);
}
document.getElementById('chart').appendChild(img);
};