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

[Solved] Dynamic model for pie chart

2 Answers 127 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.
Emir
Top achievements
Rank 1
Emir asked on 07 Apr 2012, 09:35 PM

Hi,

I am trying to use a dynamic model for pie chart and ajax binding but cant get it to work. I can't get this to load the chart. If I specify the type then it works fine.

This chart is in partial view and it will need to take care of ca 20 reports with different grouping options and I do not want to define a view for each one of them.

Please be gentle. Still a beginner. Thank a lot for your help.

@(Html.Telerik().Chart<dynamic>()
    .Name("ReportDataChart")
    .ClientEvents(events => events.OnLoad("onLoad_ReportDataChart")
        .OnDataBinding("ReportData_onDataBinding")
        .OnError("onError_ReportDataChart"))
    .Title("Report Data for:...")
    .Legend(legend => legend.Position(ChartLegendPosition.Left))
    .Series(series => {
          series.Pie("itemCount","Bucket")
              .Labels(labels => labels.Visible(true)
                  .Template(reportType.SeriesTemplate()))
          .Overlay(ChartPieSeriesOverlay.None);
      })
    .Tooltip(true)
    .DataBinding(dataBinding => dataBinding
          .Ajax().Select("LoadReportDataChart", "SRReports"))
)

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 12 Apr 2012, 11:15 AM
Hello Emir,

I reproduced the problem you wrote about. The member and category names aren't interpreted properly when the type is dynamic. We are still investigating how can this be fixed and I will write again once we have more information. A workaround for now is to set the names in the Pie SeriesDefaults and apply them in the OnLoad client-side event e.g.

.SeriesDefaults(defaults =>
  {
      defaults.Pie().Series.Member = "itemCount";
      defaults.Pie().Series.CategoryMember = "Bucket";
  })
function onLoad(e) {
    var chart = $(this).data('tChart');
    chart.options.series[0].field = chart.options.seriesDefaults.pie.field;
    chart.options.series[0].categoryField = chart.options.seriesDefaults.pie.categoryField;
}

All the best,
Daniel
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.
0
Daniel
Telerik team
answered on 21 Apr 2012, 01:27 PM
Hello again Emir,

The problem occurred because the Chart attempted to get the names with an expression used on the model. I am glad to inform you that this is fixed and the changes will be included in next official release of the Telerik MVC Extensions.


All the best,
Daniel
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
Emir
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or