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

Binding Data with EntityDataSource: X-Axis Labels

1 Answer 72 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 16 Dec 2010, 11:21 PM
Hello,

When I bind the RadChart, I get a chart with 10 bars, but the only X-Axis label is "1", while there is a legend that shows the 10 colors for each bar (column name in database table).  I would like to label the X-Axis with the database column names programmatically, and have them correspond to the chart's bars.
    <telerik:RadChart ID="RadChart1" runat="server" DataSourceID="edsGrade">
    </telerik:RadChart>

    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <telerik:RadChart ID="RadChart1" runat="server" DataSourceID="edsGrade">
    </telerik:RadChart>

    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <telerik:RadChart ID="RadChart1" runat="server" DataSourceID="edsGrade">
    </telerik:RadChart>

    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <telerik:RadChart ID="RadChart1" runat="server" DataSourceID="edsGrade">
    </telerik:RadChart>

    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
    <asp:EntityDataSource ID="edsGrade" runat="server" 
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities" 
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade" 
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>

I did something like this, but all it did was shove all the data from the db, into "Col1" and left "Col2" blank.

                    RadChart1.PlotArea.XAxis.AddItem("Str");
                    RadChart1.PlotArea.XAxis.AddItem("Aero");
                    RadChart1.PlotArea.XAxis.AddItem("Anaero");
                    RadChart1.PlotArea.XAxis.AddItem("Musc");
                    RadChart1.PlotArea.XAxis.AddItem("Cardio");
                    RadChart1.PlotArea.XAxis.AddItem("Power");
                    RadChart1.PlotArea.XAxis.AddItem("Str");
                    RadChart1.PlotArea.XAxis.AddItem("Aero");
                    RadChart1.PlotArea.XAxis.AddItem("Anaero");
                    RadChart1.PlotArea.XAxis.AddItem("Musc");
                    RadChart1.PlotArea.XAxis.AddItem("Cardio");
                    RadChart1.PlotArea.XAxis.AddItem("Power");
    <telerik:RadChart ID="RadChart1" runat="server" DataSourceID="edsGrade">
    </telerik:RadChart>
 
    <asp:EntityDataSource ID="edsGrade" runat="server"
        ConnectionString="name=BFEntities" DefaultContainerName="BFEntities"
        EnableFlattening="False" EntitySetName="Grades" EntityTypeFilter="Grade"
        AutoGenerateWhereClause="True">
        <WhereParameters>
            <asp:Parameter Name="Grades.GradeID"/>
        </WhereParameters>
    </asp:EntityDataSource>
 
...
 
RadChart1.PlotArea.XAxis.AddItem("Col1");
RadChart1.PlotArea.XAxis.AddItem("Col2");


Thanks for Your Assistance

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 22 Dec 2010, 10:45 AM
Hello Mike,

Let me start with several words on how RadChart works with the data. The columns (properties) in the datasource are represented by series in RadChart. And for every record (instance) new items are added. So, say there is a single column and 5 records. Then RadChart will create one ChartSeries with 5 ChartSeriesItems in it (i.e. by default 5 bars with separate labels and with the same color). If the columns were two, there would be 10 bars -- 5 couples, five labels along the X axis (one for each record). It would be similar to this chart.

Now, according to your description it seems your data source returns a single record with multiple columns. This will produce multiple series with one item in each of them. As each series has a single item it appears at the first position. If that is the case, I would suggest creating a single ChartSeries and adding a ChartSeriesItem to it for each column in the datasource. This will produce a bar chart with X axis item for each bar, but all the bars will appear with the same color. You can check this help topic for details on how to assign different colors.

Best regards,
Ves
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Chart (Obsolete)
Asked by
Mike
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or