Flot绘制图表然后无故重定向

发布于 2024-11-16 20:50:22 字数 3675 浏览 2 评论 0原文

我正在使用 float 来绘制一些数据图表。我在表单中输入开始日期和结束日期,然后检索要绘制图表的数据。图表暂时显示正常,但随后 url 被重定向到同一页面,但附加了“?0=on&1=on&2=on&3=on&4=on&5=on”,这并没有不存在。这是我的代码:

    <form onsubmit='formValidator()' >
        Start Date: <input type='text' id='date1' /><br />
        End Date: <input type='text' id='date2' /><br />
    <input type='submit' value='Go' />

    <div align="center"><div id="placeholder" style="width:80%; height: 700px"></div></div>

    <p id="choices" style="color:#FFFFFF">Show:</p>

    <script type="text/javascript" id="source">


function formValidator(){
    // Make quick references to our fields
    var d1 = document.getElementById('date1');
    var d2 = document.getElementById('date2');
    var msg = "Please enter the date in the format yyyymmdd. e.g. 20110609 for June 9, 2011";
    // Check each input in the order that it appears in the form!
    if(notEmpty(d1, msg)&& notEmpty(d2, msg) && isNumeric(d1, msg)&& isNumeric(d2, msg)&& lengthRestriction(d1, msg)&& lengthRestriction(d2, msg)){
        $(function () {
                var date1   = d1.value;
                var date2   = d2.value;

/* foo1-6 are arrays that get their assigned values here */

                var datasets    =   [
                    {label: "Foo1", data: foo1      },
                {label: "Foo2", data: foo2      },
                {label: "Foo3", data: foo3      },
                {label: "Foo4", data: foo4      },
                {label: "Foo5", data: foo5      },
                {label: "Foo6", data: foo6      }
                ];

                // hard-code color indices to prevent them from shifting as
                // options are turned on/off
                var i = 0;
                $.each(datasets, function(key, val) {
                    val.color = i;
                    ++i;
                });


                // insert checkboxes 
                var choiceContainer = $("#choices");
                $.each(datasets, function(key, val) {
                    choiceContainer.append('<br/><input type="checkbox" name="' + key +
                                           '" checked="checked" id="id' + key + '">' +
                                           '<label for="id' + key + '">'
                                            + val.label + '</label>');
                });
                choiceContainer.find("input").click(plotAccordingToChoices);



                function plotAccordingToChoices() {
                    var data = datasets;

                    choiceContainer.find("input:checked").each(function () {
                        var key = $(this).attr("name");
                        if (key && datasets[key])
                            data.push(datasets[key]);
                    });

                    if (data.length > 0)    {
                        var options =   {
                            legend: {
                                backgroundColor: "#000000",
                                backgroundOpacity: 0.9,
                                labelFormatter: function(label,series) {
                                    return "<div style=color:#FFFFFF>" + label + "</div>";
                                }
                            },
                            yaxis: { min: 0 },
                        }
                    };
                    $.plot($("#placeholder"), data, options);
                }

                plotAccordingToChoices();

            });
    }   
}

I'm using flot to chart some data. I input a start and end date in a form then retrieve the data to be charted. The chart displays properly for a moment, but then the url gets redirected to the same page, but appended with "?0=on&1=on&2=on&3=on&4=on&5=on" which doesn't exist. Here's my code:

    <form onsubmit='formValidator()' >
        Start Date: <input type='text' id='date1' /><br />
        End Date: <input type='text' id='date2' /><br />
    <input type='submit' value='Go' />

    <div align="center"><div id="placeholder" style="width:80%; height: 700px"></div></div>

    <p id="choices" style="color:#FFFFFF">Show:</p>

    <script type="text/javascript" id="source">


function formValidator(){
    // Make quick references to our fields
    var d1 = document.getElementById('date1');
    var d2 = document.getElementById('date2');
    var msg = "Please enter the date in the format yyyymmdd. e.g. 20110609 for June 9, 2011";
    // Check each input in the order that it appears in the form!
    if(notEmpty(d1, msg)&& notEmpty(d2, msg) && isNumeric(d1, msg)&& isNumeric(d2, msg)&& lengthRestriction(d1, msg)&& lengthRestriction(d2, msg)){
        $(function () {
                var date1   = d1.value;
                var date2   = d2.value;

/* foo1-6 are arrays that get their assigned values here */

                var datasets    =   [
                    {label: "Foo1", data: foo1      },
                {label: "Foo2", data: foo2      },
                {label: "Foo3", data: foo3      },
                {label: "Foo4", data: foo4      },
                {label: "Foo5", data: foo5      },
                {label: "Foo6", data: foo6      }
                ];

                // hard-code color indices to prevent them from shifting as
                // options are turned on/off
                var i = 0;
                $.each(datasets, function(key, val) {
                    val.color = i;
                    ++i;
                });


                // insert checkboxes 
                var choiceContainer = $("#choices");
                $.each(datasets, function(key, val) {
                    choiceContainer.append('<br/><input type="checkbox" name="' + key +
                                           '" checked="checked" id="id' + key + '">' +
                                           '<label for="id' + key + '">'
                                            + val.label + '</label>');
                });
                choiceContainer.find("input").click(plotAccordingToChoices);



                function plotAccordingToChoices() {
                    var data = datasets;

                    choiceContainer.find("input:checked").each(function () {
                        var key = $(this).attr("name");
                        if (key && datasets[key])
                            data.push(datasets[key]);
                    });

                    if (data.length > 0)    {
                        var options =   {
                            legend: {
                                backgroundColor: "#000000",
                                backgroundOpacity: 0.9,
                                labelFormatter: function(label,series) {
                                    return "<div style=color:#FFFFFF>" + label + "</div>";
                                }
                            },
                            yaxis: { min: 0 },
                        }
                    };
                    $.plot($("#placeholder"), data, options);
                }

                plotAccordingToChoices();

            });
    }   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙气飘飘 2024-11-23 20:50:22

必须得出结论,页面上还有其他一些 javascript 导致了该行为:您是否已将页面减少为仅 jquery、flot 和数据源,并确保没有其他用户提供的 javascript 导致重新加载? flot 库中没有任何内容会导致自动重新加载,因此我猜测它是您的应用程序部署的框架的一些工件。

Would have to conclude that there is some other javascript on the page that is causing that behavior: have you reduced the page to ONLY jquery, flot and the data source and ensured that you have no other user-provided javascript that is causing a reload? There is nothing in the flot library that causes an automatic reload, so I'm guessing it is some artifact of the framework your app is deployed in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文