什麼,我需要做的是加載從我的數據庫 的存儲與數據extjs4創建我的餡餅數據圖表接受這個數據,所以我需要在格式返回我的數據看起來是這樣的:使用JSON.NET序列化JSON數據 - C# - ExtJS的
var data = [{ name: "Low", data1: "20", data2: "54", data3: "63", data4: "12" },
{ name: "Moderate", data1: "2", data2: "74", data3: "13", data4: "25" },
{ name: "Critical", data1: "42", data2: "17", data3: "3", data4: "20" },
{ name: "High", data1: "25", data2: "14", data3: "23", data4: "52"}];
所以我嘗試做這在C#與json.net,我創建了一個class.cs,把我的查詢來獲得我需要的數據:
namespace charts
{
public class lineChartClass
{
public String piedata()
{
{//..my queries in here..//}
double[] data = new double[4] ;
//data = "{ name: \"Low\", data1: " + lowtotal + "}" + ",{ name: \"Moderate\", data1: " + moderatetotal + "}" + ",{ name: \"Critical\", data1: " + criticaltotal + "}" + ",{ name: \"High\", data1: " + hightotal + "}";
data[0]=lowtotal;
data[1] = moderatetotal;
data[2] = criticaltotal;
data[3] = hightotal;
return data;
}//eo piedata
}
public class ChartItem
{
public string Name { get; set; }
public string Data1 { get; set; }
}
}
,創造了我的handler.ashx轉換成JSON:
namespace charts {
public class lineChartData : IHttpHandler
{
static string ConvertToJson()
{
List<ChartItem> chartItems = new List<ChartItem>();
chartItems.Add(new ChartItem() { Name = "Low", Data1 = json[0].ToString() });
chartItems.Add(new ChartItem() { Name = "Moderate", Data1 = json[1].ToString() });
chartItems.Add(new ChartItem() { Name = "Critical", Data1 = json[2].ToString() });
chartItems.Add(new ChartItem() { Name = "High", Data1 = json[3].ToString() });
string result = new JavaScriptSerializer().Serialize(chartItems);
return result;
}
}
}
然後在我chart.js之我這樣稱呼它:
var obj= new lineChartData();
window.store1 = Ext.create('Ext.data.JsonStore', {
fields: ['name', 'dat1', 'data2', 'data3', 'data4'],
data: obj.ConvertToJson()//generateData()
});
,但我得到這個錯誤:
Uncaught ReferenceError: lineChartData is not defined
lineChartData.ashxGET http://localhost/lineChartData.ashx?proxy 500 (Internal Server Error)
IM剛開始使用C#和ExtJS的和不知道如何使用json.net
在此先感謝烏拉圭回合時間
代碼'趕上(例外){拋出前; }'是邪惡的:不要捕捉你無法處理或包裝的異常; *從不*重新拋出異常。 –
我添加它後,我得到了錯誤,刪除它dosnt改變任何東西,thx – Armance
它改變了堆棧跟蹤,從而使調試更難。 –