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

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

1 Answer 159 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Raido Valgeväli
Top achievements
Rank 2
Raido Valgeväli asked on 28 May 2013, 10:18 AM
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

1 Answer, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 30 May 2013, 08:18 AM
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!
Tags
Chart
Asked by
Raido Valgeväli
Top achievements
Rank 2
Answers by
Hristo Germanov
Telerik team
Share this question
or