繁体   English   中英

动态浮点图 jquery 库的问题

[英]Problem with dynamic flot graph jquery library

我在使用其折线图的 plot 图表时遇到问题。 What I want is to generate a java based sql query which would give me a values which I would put inside my json string variable and pass it to the data variable of javascript. 我试图做某事,但它没有更新它。 这是我的代码:

     <script>
 $(function(){
     var options = {
                lines: { show: true },
                points: { show: true },
                xaxis: { show:false,tickDecimals: 0, tickSize: 20 }
            };

            var data = [];
            var placeholder = $("#myplace");

            $.plot(placeholder, data, options);

            function update() {
                // we get all the data in one go, if we only got partial
                // data, we could merge it with what we already got
            <%
    String jsonString = "{\"label\": \"Europe (EU28)\",\"data\": [[1, 20], [20, 10], [40, 3.9], [100, 40]]}";
    out.flush();
    %>    
                data = [<%=jsonString%>];

              // console.log(series[0][1]);
                $.plot($("#myplace"), data, options);
                setTimeout(update,1000);
            }

           update();

 });
 </script>

谁能指导我应该如何进行? 谢谢

您的 Java 代码将生成一个未分配给 JavaScript 变量的字符串。 我删除了 out.flush 等无用的东西。 这是您的更新 function 的外观:

function update() {
        // we get all the data in one go, if we only got partial
        // data, we could merge it with what we already got
        data = <% "{\"label\": \"Europe (EU28)\",\"data\": [[1, 20], [20, 10], [40, 3.9], [100, 40]]}";%>;   
        $.plot($("#myplace"), data, options);
}

我还删除了 setTimeout,因为它每次都会产生相同的数据。 如果您希望您的图表从服务器重复更新,您应该查看 ajax 请求(例如 jQuery 中的 $.get)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM