0

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?

4

1 回答 1

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。按照如何:创建饼图来创建图表。

接下来,右键单击您的饼图。单击“更改图表类型...”。在选项显示中选择圆环图。

于 2018-04-20T18:35:45.043 回答