Hi all,
Now, I have been developing a sample webpart using VS 2010 Sandboxed Solution in SharePoint 2010 to display the chart (pie, bar etc) based on the list items available on the target SharePoint list. While pressing F5, it automatically deployed successfully and that custom webpart is also available in the webpart galleries. But, while dragging the custom webpart, I got the error below,
Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.
Please note that I need a solution for how to create a webpart and display the relevant charts in that custom webpart using Sandbox Solution in SharePoint 2010. Any help?...Appreciated...
I have written the code in my sample as below,
protected override void CreateChildControls()
{
try
{
Chart dashboardChart = new Chart();
Series f = new Series("Series1");
dashboardChart.Series.Add(f);
f.ChartType = SeriesChartType.Bar;
ChartArea a = new ChartArea("ChartArea1");
dashboardChart.ChartAreas.Add(a);
DataTable dt = new DataTable();
DataColumn dc;
dc = new DataColumn();
dc.ColumnName = "Name";
dt.Columns.Add(dc);
dc = new DataColumn();
dc.ColumnName = "Age";
dt.Columns.Add(dc);
DataRow dr;
dr = dt.NewRow();
dr["Name"] = "Fred";
dr["Age"] = "54";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Bill";
dr["Age"] = "66";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Rhona";
dr["Age"] = "32";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Peter";
dr["Age"] = "46";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Tina";
dr["Age"] = "26";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Ella";
dr["Age"] = "2";
dt.Rows.Add(dr);
dashboardChart.DataSource = dt;
dashboardChart.Series["Series1"].XValueMember = "Name";
dashboardChart.Series["Series1"].YValueMembers = "Age";
dashboardChart.DataBind();
this.Controls.Add(dashboardChart);
}
catch (Exception ex)
{
throw ex;
}
}