This is a migrated thread and some comments may be shown as answers.

Pie Chart with SQLDataSource Error

2 Answers 84 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Jerald
Top achievements
Rank 1
Jerald asked on 25 Jul 2018, 10:04 PM

I'm attempting to use my first RadHtmlChart (pie chart).  The SqlDataSource provides the following:

+---------------------------+--------------------+

|              stat              |    StatCount    |

+---------------------------+--------------------+
|Closed                       |         4067        | 

+---------------------------+--------------------+
|Pending Assignment |           1            |

+---------------------------+--------------------+
|QA Ready                 |       600            | 

+---------------------------+--------------------+
|In QA                        |       400             |

+---------------------------+--------------------+
|Assigned                  |      4946            |

+---------------------------+--------------------+

The 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
                                  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>

 

Error message:

Cannot create an object of type 'System.Nullable`1[[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' from its string representation 'StatCount' for the 'Y' property.

What am I doing incorrectly?

Thanks,

J

 

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Jul 2018, 03:23 PM
Hi Jerald,

When data binding the chart series you need to set its DataFieldY property to point to the field name you want to use instead of populating its SeriesItems collection: https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/data-binding/overview and https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/data-binding/sqldatasource.

If we take our SqlDataSource demo (https://demos.telerik.com/aspnet-ajax/htmlchart/examples/databinding/database/defaultcs.aspx), here's how it can look with a pie series (the result is attached below):

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
SelectCommand="SELECT [Year], [Value] FROM [Data] WHERE ([Subcategory_Id] = 1)"></asp:SqlDataSource>
 
 
<telerik:RadHtmlChart runat="server" Width="800px" Height="500px" ID="RadHtmlChart1"
    DataSourceID="SqlDataSource1">
    <PlotArea>
        <Series>
            <telerik:PieSeries DataFieldY="Value" NameField="Year">
            </telerik:PieSeries>
        </Series>
    </PlotArea>
</telerik:RadHtmlChart>

So, you'd need to define the series like this:

<telerik:PieSeries StartAngle="90" NameField="stat" DataFieldY="StatCount">
    <LabelsAppearance Position="OutsideEnd"></LabelsAppearance>
</telerik:PieSeries>


Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jerald
Top achievements
Rank 1
answered on 26 Jul 2018, 06:35 PM
Thank you very much Marin for such a quick response.  It works and your explanation was extremely helpful.
Tags
Chart (HTML5)
Asked by
Jerald
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Jerald
Top achievements
Rank 1
Share this question
or