I am trying to create a telerik reporting doughnut chart. The problem is, my values aren't in the format expected.
My data looks like this:
{ GoodHours: 120, Downtime: 43.5, PlannedTime: 12.77 }
It seems the way the charts are set up is to expect data like this:
{
Time: 60, Type: "GoodHours",
Time: 45, Type: "GoodHours",
Time: 43.5, Type: "Downtime",
Time: 15, Type: "GoodHours",
Time: 12.77, Type: "PlannedTime"
}
The reason my data is formatted this way is because it comes from a rather complex Stored Procedure that does the record aggregation itself before sending the data to the report. It's much faster to allow MsSql to crunch the numbers than getting telerik reporting to do it.
I have no clue how to even begin setting up the chart.
I followed the online instructions for creating a doughnut (pie) chart, but it assumes my data is not already digested. I tried adding multiple Series
but they ended up being displayed on different levels, sort of like doughnuts within doughnuts.
How would I set this up?
First, write your stored procedure and call it from your C# code.
Create a serializable object to store your data from the SP.
[Serializable()]
public class reportTimeTypeObj
{
public decimal time { get; set; }
public string type { get; set; }
}
Then create a function that will consume the data and transform it into the format required.
public List<reportTimeTypeObj> getTimeSpentPatientByVisitTypeObj()
{
//Create a list of objects for your donut.
reportTimeTypeObj list = new List<reportTimeTypeObj>();
//Add code to call stored procedure here
//ds is the data set returned from the stored procedure
if (ds.Tables.Count > 0)
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.Add(new reportTimeSpentPatientByVisitTypeObj()
{
time = dr["time "] != DBNull.Value ?
Convert.ToDecimal(dr["time "]) : 0,
type = dr["type "] != DBNull.Value ?
string.IsNullOrEmpty(dr["visit_type"].ToString()) ?
"Not recorded" :
Convert.ToString(dr["visit_type"]) : "Not recorded"
});
}
return list;
}
Next, create an ObjectDataSource (ODS) component using the Report Designer. Assign the function to the ODS. Follow How to: Create Pie Chart to create your chart.
Next, right click on your pie-chart. Click "Change Chart Type...". In the option shows select donut chart.