剑道UI图将不会更新采用了棱角分明(Kendo UI Chart won't update

2019-09-27 08:52发布

我使用使用剑道DataViz公司和角指令的饼图上的k的数据源。 当我改变在$范围的数据源对象,它不更新,并引发错误。 旨在角度指令使用这种方式?

这里有一个JSBin显示问题: http://jsbin.com/OSudIzEH/9/edit

角码

var app = angular.module('chart-example', ['kendo.directives']);

function ChartController($scope) {
  $scope.pie = {
    title: {
        position: "bottom",
        text: "Share of Internet Population Growth, 2007 - 2012"
    },
    legend: {
        visible: false
    },
    chartArea: {
        background: ""
    },
    seriesDefaults: {
        labels: {
            visible: true,
            background: "transparent",
            template: "#= category #: #= value#%"
        }
    },
    series: [{
        type: "pie",
        field: "value",
        categoryField: "category"
    }],
    tooltip: {
        visible: true,
        format: "{0}%"
    }
  };

  $scope.updatePie = function() {
    $scope.countries = {
    data: [
        {
            category: "Asia2",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe2",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America2",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa2",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East2",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America2",
            value: 3.6,
            color: "#033939"
        }
    ]
  };
  };

  $scope.countries = {
    data: [
        {
            category: "Asia",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America",
            value: 3.6,
            color: "#033939"
        }
    ]
  };
}

HTML

<div ng-controller="ChartController">    
    <button ng-click="updatePie()">update</button>
    <div kendo-chart k-options="pie" k-data-source="countries" />

  </div>

Answer 1:

您需要创建一个数据源剑道,然后更新它的工作数据对象。 JSBin已更新工作代码。

var app = angular.module('chart-example', ['kendo.directives']);

function ChartController($scope) {
  $scope.pie = {
    title: {
        position: "bottom",
        text: "Share of Internet Population Growth, 2007 - 2012"
    },
    legend: {
        visible: false
    },
    chartArea: {
        background: ""
    },
    seriesDefaults: {
        labels: {
            visible: true,
            background: "transparent",
            template: "#= category #: #= value#%"
        }
    },
    series: [{
        type: "pie",
        field: "value",
        categoryField: "category"
    }],
    tooltip: {
        visible: true,
        format: "{0}%"
    }
  };

  $scope.updatePie = function() {
    $scope.countries.data([
        {
            category: "Asia2",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe2",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America2",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa2",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East2",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America2",
            value: 3.6,
            color: "#033939"
        }
    ]
  );
  };

  $scope.countries = new kendo.data.DataSource({
    data: [
        {
            category: "Asia",
            value: 53.8,
            color: "#9de219"
        }, {
            category: "Europe",
            value: 16.1,
            color: "#90cc38"
        }, {
            category: "Latin America",
            value: 11.3,
            color: "#068c35"
        }, {
            category: "Africa",
            value: 9.6,
            color: "#006634"
        }, {
            category: "Middle East",
            value: 5.2,
            color: "#004d38"
        }, {
            category: "North America",
            value: 3.6,
            color: "#033939"
        }
    ]
  });
}


Answer 2:

这看起来像角剑道给我的错误。 一个问题是,对于PARAMS toDataSource是在错误的顺序。 然而,即使是固定后,小部件不会更新与新的数据源。 我做出了剑道棱角脚本进行一些更改,使这项工作(但我不知道这是否适合在与它的特点的其余部分):

// Keep the element's data up-to-date with changes.
// this will have to be $watchCollection in >= 1.1.4
scope.$watch(attrs.kDataSource, function (mew, old) {
    if (mew !== old) {
        element.data('$kendoDataSource',
            toDataSource(mew, type));

        var role = element.data("role");
        var widgetType = role.charAt(0).toUpperCase() + role.slice(1);
        var w = element.data("kendo" + widgetType);

        if (!w) {
            w = kendo.widgetInstance(element, kendo.ui);
        }

        if (w && typeof w.setDataSource === "function") {
            w.setDataSource(element.data('$kendoDataSource'));
        }
    }
}, true);

这里演示



文章来源: Kendo UI Chart won't update using Angular