Ela*_*hmi 1 asp.net jquery jqplot
我有以下jQuery代码:
$(document).ready(function () {
var group = 'test';
$.ajax({
type: "POST",
async: false,
url: "/validate.asmx/GetGraphData",
contentType: "application/json;",
data: "{'groupBy': '" + group + "'}",
dataType: 'json',
success: function (data) {
Plot(data.d);
}
});
});
function Plot(dataIn) {
alert(dataIn);
$.jqplot('chartcontainer', [[[ 'test1', 1 ], [ 'test2', 5]]],
{
seriesDefaults: {
renderer: $.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: { show: true, location: 'e' }
}
);
}
Run Code Online (Sandbox Code Playgroud)
webmethod(切割后进行测试)看起来像这样:
[WebMethod]
public string GetGraphData(string groupBy)
{
PaymentModelDataContext db = new PaymentModelDataContext();
var q = from Event in db.TrackingEvents
group Event by Event.campaignID;
//string returnJSON;
//string returnJSON = "[";
//foreach (var grp in q)
//{
// returnJSON += "['" + grp.Key + "'," + grp.Count() + "],";
//}
//returnJSON += "]";
//var ser = new JavaScriptSerializer();
//returnJSON = ser.Serialize(q);
//return returnJSON;
return "[['test1' , 1],['test2' , 5]]";
}
Run Code Online (Sandbox Code Playgroud)
如果我使用相同的字符串,我将返回此处并将其作为文本放在jquery代码中,将显示该图.我在绘图功能中发出警报,数据就像我发送的那样.有任何想法吗?
谢谢!
使用dataRenderer
$(document).ready(function(){
var ajaxDataRenderer = function(url, plot) {
var ret = null;
$.ajax({
// have to use synchronous here, else returns before data is fetched
async: false,
url: url,
dataType:'json',
success: function(data) {
ret = data;
}
});
return ret;
};
var jsonurl = "/validate.asmx/GetGraphData";
plo12 = $.jqplot('chart2', jsonurl,{
title: 'AJAX JSON Data Renderer',
dataRenderer: ajaxDataRenderer,
seriesDefaults: {
renderer: $.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: { show: true, location: 'e' }
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6408 次 |
| 最近记录: |