以下 Java 脚本函数不适用于 jcanvas 图表
The Following Java Script Function not working for jcanvas chart
<script type="text/javascript">
window.onload = function () {
debugger;
$.ajax({
type: "POST",
url: "RMDashboard.aspx/get_dept_pend_fin_wo",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
function OnSuccess(response) {
//alert(response.d)
var chart = new CanvasJS.Chart("ccpevman", {
title: {
text: ""
},
axisX: {
interval: 3,
intervalType: "month",
},
data: [{
type: "spline",
dataPoints: [ jQuery.parseJSON(response.d) ]
}]
});
chart.render();
}
}
</script>
来自cs页面的web方法returns格式为
的字符串
{ label: "08/2015", y: 25, markerColor: "Green" },{ label: "09/2015", y: 87, markerColor: "Green" },{标签:“10/2015”,y:158,markerColor:"Green"},{标签:“11/2015”,y:180,markerColor:"Green"},{标签:“12/2015 ", y: 336, markerColor: "Green" },{ label: "01/2016", y: 57, markerColor: "Green" },{ label: "02/2016", y: 187, markerColor: "Green" },{ 标签: "03/2016", y: 341, markerColor: "Green" },{ 标签: "07/2015", y: 1, markerColor: "Red" },{ 标签: "09/2015", y: 3, markerColor: "Red" },{ 标签: "10/2015", y: 2, markerColor: "Red" },{ 标签: "11/2015", y: 1, markerColor: "Red" },{ 标签: "12/2015", y: 3, markerColor: "Red" },{ 标签: "02/2016", y: 25, markerColor: "Red" },{ 标签: "03/2016", y: 33, markerColor: "Red" }
我已将其转换为 json 并应用于数据点是否有其他方法可以实现此目的。
将字符串转换为以下格式::
var objectstring =response.d;
var objectStringArray = (new Function("return [" + objectstring+ "];")());
然后将objectStringArray赋值给datapoints
dataPoints: objectStringArray
它现在对我来说工作得很好...谢谢大家
<script type="text/javascript">
window.onload = function () {
debugger;
$.ajax({
type: "POST",
url: "RMDashboard.aspx/get_dept_pend_fin_wo",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
function OnSuccess(response) {
//alert(response.d)
var chart = new CanvasJS.Chart("ccpevman", {
title: {
text: ""
},
axisX: {
interval: 3,
intervalType: "month",
},
data: [{
type: "spline",
dataPoints: [ jQuery.parseJSON(response.d) ]
}]
});
chart.render();
}
}
</script>
来自cs页面的web方法returns格式为
的字符串{ label: "08/2015", y: 25, markerColor: "Green" },{ label: "09/2015", y: 87, markerColor: "Green" },{标签:“10/2015”,y:158,markerColor:"Green"},{标签:“11/2015”,y:180,markerColor:"Green"},{标签:“12/2015 ", y: 336, markerColor: "Green" },{ label: "01/2016", y: 57, markerColor: "Green" },{ label: "02/2016", y: 187, markerColor: "Green" },{ 标签: "03/2016", y: 341, markerColor: "Green" },{ 标签: "07/2015", y: 1, markerColor: "Red" },{ 标签: "09/2015", y: 3, markerColor: "Red" },{ 标签: "10/2015", y: 2, markerColor: "Red" },{ 标签: "11/2015", y: 1, markerColor: "Red" },{ 标签: "12/2015", y: 3, markerColor: "Red" },{ 标签: "02/2016", y: 25, markerColor: "Red" },{ 标签: "03/2016", y: 33, markerColor: "Red" }
我已将其转换为 json 并应用于数据点是否有其他方法可以实现此目的。
将字符串转换为以下格式::
var objectstring =response.d;
var objectStringArray = (new Function("return [" + objectstring+ "];")());
然后将objectStringArray赋值给datapoints
dataPoints: objectStringArray
它现在对我来说工作得很好...谢谢大家