我有这个要求,我有一组图表,当我从组合框中选择图表类型时,我需要做的是重绘相同的数据列表,但我不知道如何实现这一点,需要一些请帮忙?关于这个的任何教程?更好..
答案 0 :(得分:0)
一种简单的方法是创建一个控制器/方法,将图形ID或名称作为参数,并在运行时为您生成该图形。然后使用jQuery对此控制器/方法进行ajax调用,获取生成的图形,并替换页面上的现有图形。
示例实施:
<script type="text/javascript">
$(function(){
$('select[name=graphList]').change(function(e){
e.preventDefault();
var graphID = $(this).val(); //returns the selected option's value
// make an ajax call to the method/controller to fetch the new graph HTML
$.ajax({
// append (new Date()).getTime() to url to prevent session timeout
url:"http://your_url_here/controller/method/" + graphID + "/" + (new Date()).getTime(),
success: function(data){
// data should now contain the graph HTML for the new generated graph
// simply put this html into the graph div
$('#graph').html(data);
}
});
});
});
</script>
<!-- HTML example below -->
<select name="graphList">
<option value="1">Graph 1</option>
<option value="2">Graph 2</option>
<option value="3">Graph 3</option>
</select>
<div id="graph">
</div>