what i need to do is load my pie data chart created with extjs4 with data from my database the store accept this data ,so i need to return my data in format that look like this:
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"}];
so im trying to do this in c# with json.net, i created a class.cs and put my queries to get the data i need :
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; }
}
}
and created my handler.ashx to convert to 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;
}
}
}
then in my chart.js i call it like this:
var obj= new lineChartData();
window.store1 = Ext.create('Ext.data.JsonStore', {
fields: ['name', 'dat1', 'data2', 'data3', 'data4'],
data: obj.ConvertToJson()//generateData()
});
but i get this error:
Uncaught ReferenceError: lineChartData is not defined
lineChartData.ashxGET http://localhost/lineChartData.ashx?proxy 500 (Internal Server Error)
im just starting with c# and extjs and dont know how to use json.net
thanks in advance for ur time
catch (Exception ex) { throw ex; }is evil: don't catch exceptions you cannot handle or wrap; and never rethrow exceptions.