【发布时间】:2019-02-24 22:47:17
【问题描述】:
我正在使用 Chartjs 制作折线图,但我的网络服务出现错误。这是服务的代码:
[WebMethod]
public List<object> getProgram12Months(string usersessionid)
{
List<object> iData = new List<object>();
List<string> labels = new List<string>();
//First get distinct Month Name for select Year.
string query1 = "SELECT DISTINCT TOP (100) PERCENT TimeFrame FROM dbo.CSQ_ProgramCount12Months ORDER BY TimeFrame ";
string conn = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
SqlDataAdapter dap = new SqlDataAdapter(query1, conn);
DataSet ds = new DataSet();
dap.Fill(ds);
DataTable dtLabels = ds.Tables[0];
foreach (DataRow drow in dtLabels.Rows)
{
labels.Add(drow["TimeFrame"].ToString());
}
iData.Add(labels);
return iData;
}
当我从浏览器调用该方法时,出现以下错误:
System.InvalidOperationException:生成错误 XML 文档。 ---> System.InvalidOperationException:类型 System.Collections.Generic.List`1[[System.String, mscorlib, 版本=2.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]] 不能在这种情况下使用。
我以off this为基础。
【问题讨论】:
标签: c# web-services chart.js