Creating dynamic chart on server side (conditions inside htmlhelper, razor view )

2 posts, 0 answers
  1. Raido Valgeväli
    Raido Valgeväli avatar
    26 posts
    Member since:
    May 2008

    Posted 28 May 2013 Link to this post

    Hi

    I'm generating the graph dynamically based on loaded description and data.
    The (simplified) code as follows:
    <div class="chart-wrapper">
        @(Html.Kendo().Chart()
            .Name("Chart1")
            .Transitions(false)
            .Title(d.graph_name)
            .Series(series => {
                foreach (www.Models.ChartDataItem s in d.chart_items)
                {
                    if (s.type == "area") {
                        series.Area(s.name)
                        .Aggregate(ChartSeriesAggregate.Avg);
                    }
                    if (s.type == "line")
                    {
                        series.Line(s.name)
                        .Aggregate(ChartSeriesAggregate.Avg);
                    }
                }
            })
    Is there a better (dynamic) way to set chart type without having the if/switch block?
    Besides Aggregate I have a lot of options to set for most (but not all) series. So I wouldn't need to copy the lines for every possible chart type. Is it possible in current solution to catch each series (created by e.g. .Area()) in a variable and conditionally set properties on it?
    Would the current approach to build a "very dynamic" chart in a View recommended? Is it possible build it completely in an Action instead?
    Yes, the question might be related to razor/htmlhelpers in general, still interested in recommended Kendo approach. Thanks.
     Raido
  2. Hristo Germanov
    Admin
    Hristo Germanov avatar
    703 posts

    Posted 30 May 2013 Link to this post

    Hi Raido,

    Unfortunately I can't give you better solution than yours. Please excuse us for the inconvenience.

    Regards,
    Hristo Germanov
    Telerik
    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
Back to Top