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

[Solved] Telerik MVC Chart Parametric Binding

5 Answers 229 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bahadir
Top achievements
Rank 1
Bahadir asked on 22 Aug 2011, 08:31 PM

I want to show a poll result for a specific poll question. When question list clicked i want to bind my chart with a query according to selected questionId.

So my plan was; 1. get questionId from selected question row. it's ok.

  1. defining ClientEvents.OndataBinding event on my chart. So i would be able to pass questionId with;

    function onChartDataBinding(e) { e.data = $.extend(e.data, { questionId: questionId }); }

  2. using $('#ChartPollResults').data('tChart').rebind(); on question list grid row selected event.

This scenario works when i have second grid binding according to first grids selected row. But it seems there is no ClientEvents.OnDataBinding event on chart control. And "rebind()" method isn't supported on Chart control.

The chart conrol i use is below.

@(Html.Telerik().Chart<QuestionResult>()
                            .Theme("WebBlue")
                            .Name("ChartPollResults")
                            .Title("Poll Question Choice Number vs. Choice Count")
                            .Legend(legend => legend.Position(ChartLegendPosition.Bottom))
                            .Series(series =>
                            {
                                series.Bar("ChoseCount").Name("Choice Count").Gap(5);
                            })
                            .CategoryAxis(axis => axis.Categories(o => o.ChoiceNumber))

                            .DataBinding(dataBinding => dataBinding.Ajax().Select("_PollResultChartBinding", "Poll", new { questionId = 0 }))
                            .HtmlAttributes(new { style = "width: %100px; height: 270px" })
                    )

My Controller binding method;

public ActionResult _PollResultChartBinding(int questionId = 0)
{
            //questionId = 3;
            if (!ModelState.IsValid || questionId == 0)
                return Json(new List<QuestionResult>());

            PollQuestionDefinition pollQuestion = service.Get(questionId);
            List<PollAnswer> pollAnswers = service.GetPollAnswersByQuestion(questionId);
            PollQuestionResultUI result = new PollQuestionResultUI(pollQuestion, pollAnswers);

            return Json(result.Results);
}

When i comment out //questionId = 3; line i can see the results for the question wiht Id= 3 in chart with no problem.

But i can't pass questionId to chart.

Thanks in advance.






5 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 23 Aug 2011, 04:14 PM
Hello Bahadir,

I can confirm that the Chart does not provide DataBinding client-side event. It does have a refresh method, but it can't be used to change the select options.

We will consider adding parameter to refresh and/or databinding event in future versions. For the moment you'll have to work around this limitation, for example, by placing the Chart in a partial view and updating it with ajax.

All the best,
Tsvetomir Tsonev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Max
Top achievements
Rank 1
answered on 16 Dec 2011, 12:30 AM
hey Bahadir,
Were you able to implement Telerik's suggestion? I am facing the same issue but dont know how to code the workaround suggested.
If you have any sample code please let me know - thank you!
0
Bahadir
Top achievements
Rank 1
answered on 16 Dec 2011, 01:22 AM
Hi max,

I used the chart on a Partial View and i passed my parameter on model of that partial view. It did the work for me.

Oh i just read the reply of Tsvetomir Tsonev. I did exactly what he said. I will be offline tomorrow. But if you make me remember next day i can send you some sample code.

0
Daniel Blendea
Top achievements
Rank 1
answered on 16 Dec 2011, 03:43 PM
Hi Bahadir,

I have the same problem, I'd love to see how you did the binding.
0
Max
Top achievements
Rank 1
answered on 28 Dec 2011, 06:48 AM
please please if you have a sample code that would be great.

Thank you so much!
Tags
General Discussions
Asked by
Bahadir
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Max
Top achievements
Rank 1
Bahadir
Top achievements
Rank 1
Daniel Blendea
Top achievements
Rank 1
Share this question
or