【发布时间】:2020-05-29 10:24:40
【问题描述】:
我尝试通过调用 setData() 来更新 Morris.Donut 图。但是在 setData() 方法被执行之后,图表就消失了。我在网上搜索过,但没有找到解决我的问题的方法。
我在这里所做的是:
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>
【问题讨论】:
标签: morris.js