Kendo UI Chart DataBinding未触发

时间:2015-07-25 23:47:18

标签: kendo-ui kendo-chart

我想在检查数据源后看看有多少项目。出于某种原因,我甚至无法获取dataBound或dataBinding事件。

数据实际上被传递到一个函数中,所以当创建网格时,它在本地拥有数据。

示例:http://dojo.telerik.com/IjAKo/2

源代码:

<div id="grid"></div>

<script>
  function onDataBinding(e) {
    console.log('here');
  }

  $(document).ready(function() {
    var chart = $("#grid").kendoChart({
      chartArea: {
        height: 250,
      },
      legend: {
        position: "bottom",
        labels: {
          font: "bold 10px Arial",
        }
      },
      seriesDefaults: {
        type: "column",
        spacing: 0,
        overlay: {
          gradient: "none"
        }
      },
      series: [{
        name: "ESCROW",
        color: "#cccbcb",
        data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
      }, {
        name: "NON-ESCROW",
        color: "#406f8c",
        data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
      }],
      categoryAxis: {
        line: {
          visible: false
        },
        categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Set", "Oct", "Nov", "Dec"],
        majorGridLines: {
          visible: false
        }
      },
      valueAxis: {
        labels: {
          format: "{0:N0}"
        },
        line: {
          visible: false
        },
        majorGridLines: {
          visible: false
        },
        max: 20
      },
      tooltip: {
        visible: true,
        format: "{0:N0}"
      },
      dataBinding: onDataBinding  // tried to do it here.

    });
    // tried to bind after initialization
    chart.bind("dataBound", function(e) {
      alert('here')
    });

  });
</script>

1 个答案:

答案 0 :(得分:4)

图表中没有dataBinding个事件,只有dataBound。仅当图表指定dataSource时才会触发此事件,甚至为空,因此您必须在图表中添加如此行:

dataSource: {},

还有一件事:在您的示例中,您使用本地数据,因此如果您首先创建图表然后将函数绑定到dataBound,则事件将不会触发cuz数据已绑定。在图表构造函数中定义dataBound事件:

dataBound: function(e) { console.log('data bound') },

修复示例:http://dojo.telerik.com/IjAKo/4