我在这里所做的是:
1) Initialize a Morris.Donut object
2) Make a button. When I click on the button, I will update the graph with new data.
当我运行代码时,图形显示为here。但是在单击按钮以更新图形之后,图形消失了。
我的代码
<div id="donut-chart" style="height: 200px;" data-width="100"></div>
<button type='button' class='update-chart'>Update chart</button>
<script type="text/javascript">
$(document).ready(function () {
// Initialize a Morris.Donut object
donut_chart = Morris.Donut({
element: 'donut-chart',
data: [
{'label': 'Yes', 'value': 1},
{'label': 'No', 'value': 0},
]
});
// Update the Morris.Donut object
$('.update-chart').on('click', function(){
line = {
element: 'donut-chart',
data: [
{'label': 'Yes', 'value': 2},
{'label': 'No', 'value': 0},
],
};
donut_chart.setData(line); // This code makes the graph disapears
});
});
</script>
我尝试通过对其调用setData()来更新Morris.Donut图。但是在执行setData()方法后,图形消失了。我已经在网上搜索了,但是找不到解决我问题的方法。 ...
donut_chart.setData(line.data);