5.14. 异步加载图表
在看板模板内,除了通过为静态<div>元素设置dg-chart-widget属性定义图表外, 也可以使用看板对象的 loadChart 函数异步加载图表:
示例:
<html>
<head>
<script type="text/javascript">
$(document).ready(function()
{
$("#loadButton1").click(function()
{
dashboard.loadChart($("#chart1"), "[a chart widget id]");
});
$("#loadButton2").click(function()
{
var $chart2 = $("<div id="chart2"></div>").appendTo(document.body);
dashboard.loadChart($chart2, "[a chart widget id]",
function(chart)
{
alert("chart ["+chart.id+"] loaded");
});
});
$("#removeButton2").click(function()
{
dashboard.removeChart("chart2");
});
});
</script>
</head>
<body>
<button id="loadButton1">加载图表1</button>
<div id="chart1"></div>
<button id="loadButton2">加载图表2</button>
<button id="removeButton2">删除图表2</button>
</body>
</html>