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

Setting the Chart theme from the controller

2 Answers 95 Views
Chart
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 04 Feb 2013, 02:59 PM
I've got a chart, which I want to be able to dynamically set the theme for - based upon a value set in a ViewBag variable.

I can do this if the chart is defined in JavaScript, however I can't seem to set it when the chart is defined using the helper.

i.e.:-
@(Html.Kendo().Chart<CMS_2013.Models.Temp_Data_Summary>()
      .Name("Chart")
      .Legend(false)
      .Title("Data in Temporary Pricing Table")
      .DataSource(dataSource => dataSource
          .Read(read => read.Action("GetSummaryChartData", "Pricing"))          
      )
      .Series(series => {
          series.Column(d => d.Records).Tooltip(true) ;
          
      })
      .CategoryAxis(axis => axis
          .Categories(model => model.Class)
      )
       
      .HtmlAttributes(new { style = "width:350px; height:250px;"})
)
If I do:-

.Theme(ViewBag.SelectedTheme) - the page returns an error.  How can I do this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 06 Feb 2013, 10:56 AM
Hello,

Although the ViewBag is dynamic, an explicit cast will still be needed in this scenario e.g.

.Theme((string)ViewBag.SelectedTheme)
Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 06 Feb 2013, 12:01 PM
Thanks, I did try ToString() , but not (string).

It's working well now.
Tags
Chart
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Daniel
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or