本文介绍了dataRender在jqPlot从ASP.NET Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图呈现从AJAX请求jqPlot条形图,我无法得到它的工作。
I am trying to render a jqPlot bar chart from an AJAX request and I can't get it to work.
我有以下的JavaScript code:
I have the following JavaScript code:
var ajaxDataRenderer = function (url, plot) {
var ret = null;
$.ajax({
// have to use synchronous here, else returns before data is fetched
async: false,
url: url,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
ret = data;
}
});
return ret;
};
var jsonurl = "WebService1.asmx/HelloWorld";
plo12 = $.jqplot('chart2', jsonurl, {
title: 'AJAX JSON Data Renderer',
dataRenderer: ajaxDataRenderer,
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {
// Put a 30 pixel margin between bars.
barMargin: 30,
// Highlight bars when mouse button pressed.
// Disables default highlighting on mouse over.
highlightMouseDown: true
},
pointLabels: { show: true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
},
yaxis: {
// Don't pad out the bottom of the data range. By default,
// axes scaled as if data extended 10% above and below the
// actual range to prevent data points right on grid boundaries.
// Don't want to do that here.
padMin: 0
}
},
legend: {
show: true,
location: 'e',
placement: 'outside'
}
});
和我的 WebService1.asmx
是这样的:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService {
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
return "[[2],[7],[14]]";
}
}
我已经看到解决方案,但我是新来这一点,我想不出我的问题是什么。
I have seen this solution, but I am new to this and I can't figure out what my problem is.
推荐答案
您可以设置RET = [数据]
You can try with setting ret = [data]
jqPlot预计阵列格式的对象以呈现图表。
jqPlot expects an object in array format to render the charts.
感谢
这篇关于dataRender在jqPlot从ASP.NET Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!