This is a migrated thread and some comments may be shown as answers.
How to change the ColumnSeries Name programatically
1 Answer 27 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Tim asked on 29 May 2013, 02:33 PM
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
    'Setting pragmatically the XAxis values
    TopRiskFactors.PlotArea.XAxis.DataLabelsField = "Name"
End Sub
Private Function GetData(ByVal Assessment As List(Of ExtendedRiskAssessment)) As DataSet
    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)

1 Answer, 1 is accepted

Sort by
Stamo Gochev
Telerik team
answered on 03 Jun 2013, 12:44 PM
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"
'data binding
ColumnChart.DataSource = GetData()

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.

Stamo Gochev
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.
Asked by
Top achievements
Rank 1
Answers by
Stamo Gochev
Telerik team
Share this question