我正在使用highcharts
在asp.net webforms
中创建图表。我对一个Web服务进行了ajax调用,作为回报,它给了我一个只包含标题名称的json结果。
如果我将此值硬编码发送到图表方法,它可以正常工作,但是当我放置json数据而不是硬编码标题时,图表不会呈现。
$.ajax({
type: "POST",
url: "OssmWebService.asmx/FillChart",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(mWhereParam),
dataType: "json",
success: function (data1) {
var a = data1.d[0];
Highcharts.chart('container1', {
title: a.titlename,
subtitle: {
text: 'Source: thesolarfoundation.com'
},
yAxis: {
title: {
text: 'Number of Employees'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
pointStart: 2010
}
},
series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}, {
name: 'Manufacturing',
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
}, {
name: 'Sales & Distribution',
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
}, {
name: 'Project Development',
data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
}, {
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}]
});
ajax成功的数据:
"{ text: 'Basic Requirement' }"
如果我将这些数据和硬编码放在title属性中,它会起作用,但如果我将这些数据直接提供给属性,就像我在上面的代码中所做的那样
a = data1.d[0];
title: a.titlename;
我的C#代码
[WebMethod]
public List<sampleDatalist> FillChart(string arrSelectedValues)
{
List<sampleDatalist> sample = new List<sampleDatalist>();
sample.Add(new sampleDatalist { titlename = "{ text: 'Basic Requirement' }" });
return sample;
}
public class sampleDatalist
{
public string titlename;
}
更新: 因为bob建议将我的属性转换为对象
我的C#将是
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<sampleDatalist> FillChart(string arrSelectedValues)
{
Object a = " { text: 'Basic Requirement' }";
List<sampleDatalist> smList = new List<sampleDatalist>();
smList.Add(new sampleDatalist { titlename = a });
return smList;
}
public class sampleDatalist
{
public Object titlename;
}
问题仍然存在。