Telerik RadHtmlChart饼图错误

时间:2018-07-25 22:20:54

标签: telerik pie-chart radgrid

我正在尝试使用RadHtmlChart饼图,但出现以下错误:

  

无法从其字符串表示形式“ StatCount”的“ Y”属性创建类型为“ System.Nullable”的对象。

如果我对asp:Chart使用相同的SqlDataSource,则它将按预期工作。所以我的猜测是RadHtmlChart特有的-但这只是猜测。

查询(MS SQL Server 2012)返回以下内容:

+----------------------+-----------------+
|         stat         |    StatCount    |
+----------------------+-----------------+
|        Closed        |      4067       | 
+----------------------+-----------------+
|   Pending Assignment |        1        |
+----------------------+-----------------+
|       QA Ready       |       600       | 
+----------------------+-----------------+
|        In QA         |       400       |
+----------------------+-----------------+
|       Assigned       |      4946       |
+----------------------+-----------------+

这是我用来获取此数据的SqlDataSource:

<asp:SqlDataSource 
    ID="sdsAssnmtStats"
    runat="server"
    ConnectionString='<%$ ConnectionStrings:DefaultConnection %>' 
    SelectCommand="SELECT s.stat ,cast(case s.stat when 'Pending Assignment' then count(a.clmNo) when 'Assigned' then count(a.clmNo) when 'QA Ready' then count(a.clmNo) when 'In QA' then count(a.clmNo) when 'Closed' then count(a.clmNo) else 0 end as nvarchar) as StatCount FROM assnmts a inner join assnmtStats astats on a.assnmtIdPk = astats.assnmtIdFk inner join stats s on astats.aStatId = s.statIdPk inner join repAssnmts ra on a.assnmtIdPk = ra.assnmtIdFk inner join aspnetusers anu on ra.repId = anu.Id inner join clients c on a.clientIdFk = c.clientIdPk inner join carrs on a.carrierId = carrs.carrIdPk inner join (SELECT a2.assnmtIdPk, MAX(astats2.asCrtdDt) as MaxDate FROM assnmts a2 INNER JOIN assnmtStats astats2 on a2.assnmtIdPk = astats2.assnmtIdFk GROUP BY a2.assnmtIdPk) mdt on a.assnmtIdPk = mdt.assnmtIdPk and astats.asCrtdDt = mdt.MaxDate inner join (select a3.assnmtIdPk, MAX(ra2.raCrtdDt) as MaxRepDate from assnmts a3 inner join repAssnmts ra2 on a3.assnmtIdPk = ra2.assnmtIdFk group by a3.assnmtIdPk) mrepdt on a.assnmtIdPk = mrepdt.assnmtIdPk and ra.raCrtdDt = mrepdt.MaxRepDate group by s.stat">
</asp:SqlDataSource>

这是RadHtmlChart:

<telerik:RadHtmlChart runat="server" ID="rhc_assnmtStats" Transitions="true" Skin="Default" DataSourceID="sdsAssnmtStats" >
        <PlotArea>
            <Series>
                <telerik:PieSeries StartAngle="90">
                    <LabelsAppearance Position="OutsideEnd"></LabelsAppearance>
                    <SeriesItems>
                        <telerik:PieSeriesItem Exploded="true" Name="stat" Visible="true" VisibleInLegend="true" Y="StatCount" />
                    </SeriesItems>
                </telerik:PieSeries>
            </Series>
        </PlotArea>
        <Legend>
            <Appearance Position="Right" Visible="true"></Appearance>
        </Legend>
        <ChartTitle Text="Assignment Counts by Status">
            <Appearance Align="Center" Position="Top"></Appearance>
        </ChartTitle>
    </telerik:RadHtmlChart>

这是我使用的asp:Chart标记,可以按预期工作:

<asp:Chart ID="assnmtStats" runat="server" DataSourceID="sdsAssnmtStats">
            <Titles>
                <asp:Title Font="Times New Roman, 14pt, style=Bold, Italic" Name="AssnmtStatsTitle" Text="Assignment Counts by Status"></asp:Title>
            </Titles>
            <Series>
                <asp:Series Name="Series1" ChartType="Pie" XValueMember="stat" YValueMembers="StatCount" YValueType="Int32" Legend="assnmtStatsLegend" IsValueShownAsLabel="true"></asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="assnmtStatsChartArea" Area3DStyle-Enable3D="true"></asp:ChartArea>
            </ChartAreas>
            <Legends>
                <asp:Legend Name="assnmtStatsLegend" Alignment="Center"></asp:Legend>
            </Legends>
        </asp:Chart>

要使RadHtmlChart正常工作,我需要做什么?

这是我在Visual Studio 2017中创建的ASP.net C#WebForms应用程序。

1 个答案:

答案 0 :(得分:0)

我收到了Telerik的解决方案。我希望这对其他在将站点上的演示从条形图转换为饼形图时遇到问题的人有所帮助。

  

当数据绑定图表系列时,您需要将其DataFieldY属性设置为指向要使用的字段名称,而不是填充其SeriesItems集合。

这是可行的解决方案:

<telerik:RadHtmlChart runat="server" ID="rhc_assnmtStats" Transitions="true" Skin="Default" DataSourceID="sdsAssnmtStats" >
            <PlotArea>
                <Series>
                    <telerik:PieSeries StartAngle="90" NameField="stat" DataFieldY="StatCount">
                        <LabelsAppearance Position="OutsideEnd"></LabelsAppearance>
                    </telerik:PieSeries>
                </Series>
            </PlotArea>
            <Legend>
                <Appearance Position="Right" Visible="true"></Appearance>
            </Legend>
            <ChartTitle Text="Assignment Counts by Status">
                <Appearance Align="Center" Position="Top"></Appearance>
            </ChartTitle>
        </telerik:RadHtmlChart>