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

Ajax binding to a complex type

2 Answers 41 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Williams
Top achievements
Rank 1
Chris Williams asked on 23 May 2012, 07:10 AM
I've been using the chart control in server binding mode for awhile, but now I have a need to use Ajax binding on a specific page.
In server binding, I bind to a complex type called a UIReport.  A UIReport is a representation of an actual chart with a collection of UIDataSeries. The UIDataSeries types contain the chart type that should display the data, the data values for the series, and the series name, among other values.

In server binding mode, I've been using the following approach, because I need to choose the chart type at run time:
.Series(series =>
            {
                foreach (var dataSeries in Model.Report.DataSeriesCollection)
                {
                    switch (dataSeries.ChartType)
                    {
                        case ChartType.Area:
                            series.Area(dataSeries.Values).Name(dataSeries.Description);
                            break;
                        case ChartType.Bar:
                            series.Bar(dataSeries.Values).Name(dataSeries.Description);
                            break;
                        case ChartType.StackedBar:
                            series.Bar(dataSeries.Values).Name(dataSeries.Description).Stack(true);
                            break;
                        case ChartType.Column:
                            series.Column(dataSeries.Values).Name(dataSeries.Description);
                            break;
                        case ChartType.StackedColumn:
                            series.Column(dataSeries.Values).Name(dataSeries.Description).Stack(true);
                            break;
                        case ChartType.Line:
                            series.Line(dataSeries.Values).Name(dataSeries.Description);
                            break;
                        case ChartType.Pie:
                            series.Pie(dataSeries.Values).Name(dataSeries.Description);
                            break;
                    }
                }
            })

How should I approach this in Ajax binding?  What value should I use in the "foreach" at the top of the Series configuration, if indeed this is supported at all? I've looked at the Ajax sample and it seems more straightforward.

My Ajax controller basically does something like this:
UIReport myreport = GetUIReport();
return new JSON(myreport);

Thanks for any pointers.

Chris



2 Answers, 1 is accepted

Sort by
0
Chris Williams
Top achievements
Rank 1
answered on 23 May 2012, 05:23 PM
Looking into this more, I see that I should probably provide a List of my UIDataSeries out of the ContentResult that provides the Ajax data.  But, I'm still not seeing if it is possible to create a series of an indeterminant chart type based on data coming back from the json ajax query.
Do you have to hook up the client event onDataBound and do this through javascript?

thanks
0
Petur Subev
Telerik team
answered on 28 May 2012, 09:45 AM
Hello Chris,

If I understand your scenario correctly you want to change the series types on the client. If so - I am afraid that this is not supported and your scenario cannot be easily work-arounded on the client.

Greetings,
Petur Subev
the Telerik team
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Chart
Asked by
Chris Williams
Top achievements
Rank 1
Answers by
Chris Williams
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or