以下逻辑运行网页的加载并调用分部 View 以在图表中显示数据:
<img src='@Url.Action("_GetChartDetails", "Chart", new { chartType = "Won" })' id="chartid" />
这有效。
但是当我从 javascript 执行此操作时,图像是空白的。谁能建议我可能做错了什么?
$http.get("http://localhost:51666/Chart/_GetChartDetails?chartType=Loss")
.success(function (response) {
alert(response);
//$("#chartid").attr("src", "data:image/png;base64," + response);
document.getElementById("chartid").src = response;
}).error(function (data, status, headers, config) {
alert(data);
});
最佳答案
与其手动执行 $http.get
来生成图表,为什么不直接更改图像源以指向部分 View 并传递所需的参数(赢得或失去) :
$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);
};
关于javascript - 正在加载 ASP :chart from javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35982800/