How to change the ColumnSeries Name programatically

2 posts, 0 answers
  1. Tim
    Tim avatar
    40 posts
    Member since:
    Sep 2012

    Posted 29 May 2013 Link to this post

    Since i cannot do the below
    <telerik:ColumnSeries Name='<%# Master.GetTranslation("Choice1")%>' DataFieldY="RiskChoice1">

    Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event. Telerik.Web.UI.ColumnSeries does not have a DataBinding event.


    I'm wondering how I can do this from the code behind, here's how i'm currently building the Chart
    Private Sub DoChart4(ByVal Assessment As List(Of ExtendedRiskAssessment))
        Dim myDS As DataSet = GetData(Assessment)
     
        TopRiskFactors.ChartTitle.Text = Master.GetTranslation("ChartRiskFactors").ToString
        TopRiskFactors.ChartTitle.Appearance.TextStyle.Bold = True
        TopRiskFactors.PlotArea.XAxis.TitleAppearance.TextStyle.Bold = True
        TopRiskFactors.PlotArea.YAxis.TitleAppearance.TextStyle.Bold = True
     
        TopRiskFactors.PlotArea.XAxis.TitleAppearance.Text = Master.GetTranslation("RiskFactors").ToString
        TopRiskFactors.PlotArea.YAxis.TitleAppearance.Text = Master.GetTranslation("RiskChoices").ToString
     
        TopRiskFactors.DataSource = myDS
        TopRiskFactors.DataBind()
     
        'Setting pragmatically the XAxis values
        TopRiskFactors.PlotArea.XAxis.DataLabelsField = "Name"
    End Sub
     
     
    Private Function GetData(ByVal Assessment As List(Of ExtendedRiskAssessment)) As DataSet
     
        returnRiskCount(Assessment)
     
        Dim ds As New DataSet("Risk")
        Dim dt As New DataTable("RiskFactors")
        dt.Columns.Add("Id", Type.[GetType]("System.Int32"))
        dt.Columns.Add("Name", Type.[GetType]("System.String"))
        dt.Columns.Add("RiskChoice1", Type.[GetType]("System.Int32"))
        dt.Columns.Add("RiskChoice2", Type.[GetType]("System.Int32"))
        dt.Columns.Add("RiskChoice3", Type.[GetType]("System.Int32"))
        dt.Columns.Add("RiskChoice4", Type.[GetType]("System.Int32"))
        dt.Columns.Add("RiskChoice5", Type.[GetType]("System.Int32"))
     
        '****
        Dim Choices As countRiskChoice = Risk.Item(1)
        dt.Rows.Add(1, Master.GetTranslation("AgreementMateriality").ToString, returnCount(Choices).Count1, returnCount(Choices).Count2, returnCount(Choices).Count3, returnCount(Choices).Count4, returnCount(Choices).Count5)
        '****
       'Etc.



  2. Stamo Gochev
    Admin
    Stamo Gochev avatar
    157 posts

    Posted 03 Jun 2013 Link to this post

    Hi Tim,

    The RadHtmlChart doesn't support evaluating such data bind expressions (setting the name of the ColumnSeries by assigning a value from a data source). That is why you get the error on the line
    <telerik:ColumnSeries Name='<%# Master.GetTranslation("Choice1")%>' DataFieldY="RiskChoice1">

    as the ColumnSeries doesn't have a data binding handler for this scenario.

    What you could do in this case is to set the name of the ColumnSeries from the code-behind. The following example shows this by using a separate function for this purpose:
    Dim column As New ColumnSeries()
    'set the name
    column.Name = GetSeriesName()
     
    column.DataFieldY = "value"
    ColumnChart.PlotArea.Series.Add(column)
     
    'data binding
    ColumnChart.DataSource = GetData()
    ColumnChart.DataBind()

    You could replace the GetSeriesName() function with the one you like. I also attach a sample page with the full example, so that you could test it.

    Regards,
    Stamo Gochev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top