【问题标题】:select from combo box and redraw the chart从组合框中选择并重绘图表
【发布时间】:2010-12-11 19:27:28
【问题描述】:

我有这个要求,我有一组图表,当我从组合框中选择图表类型时,我需要为相同的数据列表重新绘制它们,但我不知道如何实现这一点,需要一些请帮忙?有这方面的教程吗?更好..

【问题讨论】:

  • 您现有的图表是如何生成的?显示一些代码,或者更好地解释。
  • 这是使用 codeigniter 完成的,我在该文件中有一个名为 view_chart.php 的视图我有这个代码 $FC = new FusionCharts("Column3D","600","300"); Column3D 是图表类型。当我从该列表中选择一个图表时,我必须在此页面中显示一个组合框 $FC = new FusionCharts(..);必须更改图表类型并重新加载页面?
  • 这是我获得此图表功能的来源codeigniter.com/forums/viewthread/169233

标签: php jquery codeigniter


【解决方案1】:

一种简单的方法是创建一个控制器/方法,将图形 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>

【讨论】:

  • 我应该在jquery中使用什么方法??
  • 如果你有请分享一些例子好吗?参考实施的链接??
猜你喜欢
  • 2017-05-01
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 1970-01-01
  • 2013-12-04
相关资源
最近更新 更多