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

Observable parameter changes data source

3 Answers 142 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
rwb
Top achievements
Rank 2
rwb asked on 08 Dec 2017, 06:11 PM

I want to make a simple example where dragging the slider updates the pie chart.

How?

I don't understand how to makethe graph data depend on the value of the slider.

 

        var viewModel = kendo.observable({
            turnips: 35,
            coconuts: function() {
                data: [{
                    category: "Big",
                    value: this.get("turnips"),
                    color: "#9de219"
                }, {
                    category: "Small",
                    value: 100 - 10 - this.get("turnips"),
                    color: "#90cc38"
                }, {
                    category: "As big as your head",
                    value: 10,
                    color: "#068c35"
                }]
            }
        });

        $(document).ready(function () {
            var slider = $("#slider").kendoSlider({
                min: 30,
                max: 60,
                smallStep: 1,
                largeStep: 5,
                showButtons: false
            }).data("kendoSlider");

            $("#elt1").kendoChart({
                title: {
                    position: "bottom",
                    text: "Coconuts"
                },
                legend: {
                    visible: false
                },
                chartArea: {
                    background: ""
                },
                seriesDefaults: {
                    labels: {
                        visible: true,
                        background: "transparent",
                        template: "#= category #: \n #= value#%"
                    }
                },
                series: [{
                    type: "pie",
                    startAngle: 90,
                    data: viewModel.coconuts
                }],
                tooltip: {
                    visible: true,
                    format: "{0}%"
                }
            });


            kendo.bind($('#view'), viewModel);
        });

3 Answers, 1 is accepted

Sort by
0
rwb
Top achievements
Rank 2
answered on 08 Dec 2017, 07:00 PM

https://dojo.telerik.com/oCuGug/3

 

This ought to be so simple but it's absolutely bloody impossible.

0
rwb
Top achievements
Rank 2
answered on 10 Dec 2017, 01:32 PM
https://dojo.telerik.com/EFigu
0
Dimitar
Telerik team
answered on 12 Dec 2017, 11:36 AM
Hello Richard,

I am glad to see that you have managed to successfully resolve the issue that you were facing. 

You have indeed figured out how to properly retrieve the "big" field value of the ViewModel by using the get() method.

Thank you for sharing the solution.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MVVM
Asked by
rwb
Top achievements
Rank 2
Answers by
rwb
Top achievements
Rank 2
Dimitar
Telerik team
Share this question
or