我正在尝试创建一个报告圆环图的telerik。问题是,我的值不是预期的格式。
我的数据如下:
{ GoodHours: 120, Downtime: 43.5, PlannedTime: 12.77 }
图表的设置方式似乎是期望这样的数据:
{
Time: 60, Type: "GoodHours",
Time: 45, Type: "GoodHours",
Time: 43.5, Type: "Downtime",
Time: 15, Type: "GoodHours",
Time: 12.77, Type: "PlannedTime"
}
我的数据以这种方式格式化的原因是因为它来自一个相当复杂的存储过程,它在将数据发送到报表之前执行记录聚合。允许MsSql处理数字比使用telerik报告要快得多。
我有没有线索如何开始设置图表。
我按照在线说明创建了甜甜圈(馅饼)图表,但它假设我的数据尚未被消化。我尝试添加多个Series
,但它们最终显示在不同的级别上,有点像甜甜圈内的甜甜圈。
我该如何设置?
答案 0 :(得分:1)
首先,编写存储过程并从C#代码中调用它。
创建一个可序列化的对象来存储来自SP的数据。
[Serializable()]
public class reportTimeTypeObj
{
public decimal time { get; set; }
public string type { get; set; }
}
然后创建一个消耗数据并将其转换为所需格式的函数。
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;
}
接下来,使用报表设计器创建ObjectDataSource(ODS)组件。将功能分配给ODS。按照How to: Create Pie Chart创建图表。
接下来,右键单击饼图。单击&#34;更改图表类型...&#34;。在选项中显示选择圆环图。