Setting the Chart theme from the controller

3 posts, 1 answers
  1. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 04 Feb 2013 Link to this post

    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. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 06 Feb 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 06 Feb 2013 Link to this post

    Thanks, I did try ToString() , but not (string).

    It's working well now.
Back to Top