Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript D3.js和JSP-数据刷新未发生_Javascript_Jsp_D3.js - Fatal编程技术网

Javascript D3.js和JSP-数据刷新未发生

Javascript D3.js和JSP-数据刷新未发生,javascript,jsp,d3.js,Javascript,Jsp,D3.js,我已经在一个JSP文件中用d3js创建了一个树状图布局。我连接到一个数据库,将数据呈现到一个JSON文件中,然后显示数据。现在我有两个文本框,在其中输入我的“开始”和“结束”日期,然后单击提交。再次连接到数据库,并用新数据重新加载相同的JSON文件。但是树映射在这里没有刷新。我在这里搞不清楚这个问题。请帮忙。代码如下 <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>

我已经在一个JSP文件中用d3js创建了一个树状图布局。我连接到一个数据库,将数据呈现到一个JSON文件中,然后显示数据。现在我有两个文本框,在其中输入我的“开始”和“结束”日期,然后单击提交。再次连接到数据库,并用新数据重新加载相同的JSON文件。但是树映射在这里没有刷新。我在这里搞不清楚这个问题。请帮忙。代码如下

<%@page contentType="text/html" pageEncoding="UTF-8"%>

    <!DOCTYPE html>
    <html lang="en">

    <head>
    <meta charset="utf-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
    <script type="text/javaScript" src="d3/d3.js"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
   <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
   <link rel="stylesheet" href="/resources/demos/style.css">
   <style>
    div.bar {
                display: inline-block;
                width: 20px;
                height: 75px;   /* We'll override height later */
                margin-right: 2px;
                background-color: brown;
                }

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  <!-- margin: 50px 50px; -->
  margin: auto;
  position: relative;
  width: 1000px;
  height:550px;
}

form {
  position: absolute;
  left: 20px;
  bottom: 10px;
}

.node {
  border: solid 1px white;
  font: 10px sans-serif;
  line-height: 12px;
  overflow: hidden;
  position: absolute;
  text-indent: 2px;
 }

 #tooltip {
        position: absolute;
        width: 200px;
        height: auto;
        padding: 10px;
        background-color: white;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
        -webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        -moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        pointer-events: none;
}

#tooltip.hidden {
        display: none;
}

#tooltip p {
        margin: 0;
        font-family: sans-serif;
        font-size: 16px;
        line-height: 20px;
}
.lables {
  border: solid 1px white;
  font: 10px sans-serif;
  line-height: 12px;
  overflow: hidden;
  position: absolute;
  text-indent: 5px;
 }

</style>

 <% response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 
 response.setHeader("Pragma","no-cache"); //HTTP 1.0 
 response.setDateHeader ("Expires", 0); //prevents caching at the proxy server  
%>

</head>
<body>
    <H4> A POC On D3.js with TreeMap Layout </H4>
        <form class="lables" action="Treemap_fetch.jsp">
                <label><input  type="radio" name="mode" value="size" checked> Clicks</label>    
        <label><input type="radio" name="mode" value="ctr"> Ctr</label> 
        <label><input type="radio" name="mode" value="searches"> Searches</label>                
                <br> <br>
                <label>From</label>
                <input type="text" id="from" name="from">
                <label>to</label>
                <input type="text" id="to" name="to">
                <input type="submit" value="Submit"> <!-- onClick=fetch() -->
                <div id="myDiv"></div>
    </form>        
    <div id="tooltip" class="hidden">
        <!-- <p><strong>Label</strong></p> -->
         <p><span id="value"></span></p> 
        </div>

        <%@page import="com.aol.poc.d3js.dbConnect.NetezzaJdbcConnection,com.aol.poc.d3js.properties.*" %>
        <%@page import="com.aol.poc.d3js.treemap.CsvToJson_V2,java.text.SimpleDateFormat,java.util.Date"%>

        <% 

        //String mode = request.getParameter("mode");
        String from="",to="";
        from = request.getParameter("from");
        to = request.getParameter("to");    

        NetezzaJdbcConnection njc = new NetezzaJdbcConnection();
        CsvToJson_V2 readCsv = new CsvToJson_V2();

        if(from == null || to == null){
            System.out.println("Inside if null");
            njc.extractData();
        }            
        else{
            System.out.println("Inside else");
            njc.extractData(from,to);
        }


            readCsv.readCsv(); 


       %>



<script>

 //var margin = {top: 40, right: 10, bottom: 10, left: 10},
  var margin = {top: 0, right: 0, bottom: 0, left: 0},
    width = 1200 - margin.left - margin.right,
    height = 450 - margin.top - margin.bottom;

//var width = 500; var height = 500;

var color = d3.scale.category20();

var treemap = d3.layout.treemap()
    .size([width, height])
    .sticky(true)
    .value(function(d) { return d.clicks; });   

var svg = d3.select("body")         
            .append("svg")
            .attr("width", width + margin.left + margin.right )
            .attr("height", height + margin.top + margin.bottom)
            .append("g");

    d3.json("data/OuputJSON.json", function(error,root){

    //alert("Inside json");
    var rects = svg.datum(root)
            .selectAll("rect")
            .data(treemap.nodes)
            .enter()
            .append("rect")
                        .call(position);

    var texts = svg.selectAll("text") 
                        .data(treemap.nodes)
                        .enter()
                        .append("text")
                        .call(textPrint);

    //Tooltip and highlighting starts
    d3.selectAll("rect").on("mouseover",mouseover); 
    d3.selectAll("rect").on("mouseout",mouseout); 
    //Tooltip and Highlighting ends

    //Transition of the Treemap.
    d3.selectAll("input").on("change",change);                          

    function change(){

        var value = this.value;
        if (this.value === "ctr") { value =  function(d) {return d.ctr;}}
        else if (this.value === "searches") { value = function(d) {return d.searches;}}
        else { value = function(d) {return d.clicks;}}    
        //alert(value);
        rects
            .data(treemap.value(value).nodes)
            .transition()           
            .duration(1500)
            .call(position);    

        texts
            .data(treemap.value(value).nodes)
            .transition()
            .delay(1500)
            .duration(500)
            .call(textPrint);
        }//change

}); //d3.json

function position(){

        this.attr("x", function(d) {return d.x;})
            .attr("y", function(d) {return d.y;})
            .attr("width", function(d) {return d.dx;})
            .attr("height", function(d) {return d.dy;})
            .attr("stroke","white")
            .attr("fill", function(d) {   //color(d.sub_group); });//return "teal" });
                        if(d.children == null)
                 return color(d.parent.sub_group); // color(d.parent.name);
            else
                 return null;                       
            });
}

function textPrint(){
    this.attr("x",function(d) {return d.x + 3;})
    .attr("y",function(d) {return d.y + 10;})
    .attr("class","node")                   
    .text(function(d){
            if(d.dx <= 10 || d.dy <= 10){ return ""; } //If the rect is too small do not display the text
                else if (d.children == null){
                    var pxK = 6.6,txtLngth = (d.clientid).length,txtAccomadate = Math.round(d.dx/pxK);
                    if (txtAccomadate >= txtLngth)                                      
                        return d.clientid;                              
                    else 
            return "";
                // return (d.clientid).substr(0,txtAccomadate);
        }
        else
                    return null;
        });
}

function mouseover(d){  

    // The below code is used for highlighting the element (i.e. rect) on mouse hover 
    d3.select(this)
      .attr("fill", "orange");

    //Get this rects x/y values, then augment for the tooltip
    var xPosition = parseFloat(d3.select(this).attr("x")) + (d.dx)/2;
    var yPosition = parseFloat(d3.select(this).attr("y")) + (d.dy)/2;

    //Update the tooltip position and value
    d3.select("#tooltip")
    .style("left", xPosition + "px")
    .style("top", yPosition + "px")
    .select("#value")
    .text(d.parent.sub_group+"--"+d.clientid);

    //Show the tooltip
    d3.select("#tooltip").classed("hidden", false);         

}

function mouseout(d) {    

    d3.select(this)
    .transition()
    .duration(500)
    .attr("fill", function(d) {
    if(d.children == null)
        return color(d.parent.sub_group);
    else
        return null;                        
    })

    //Hide the tooltip
    d3.select("#tooltip").classed("hidden", true);  

}
</script>
</body> 
</html>

你能把你的密码贴出来吗?我已经加了密码。我知道这个问题可能是因为浏览器缓存。但我还添加了清除缓存的代码。这又没用了。你确认你得到的数据确实不同了吗?是的,我确认了。数据是不同的。第一次加载页面后,我将清除所有浏览器缓存,然后在“检测”框中给出“开始”和“结束”日期。我做了一个提交,树映射数据也被改变了。但是,如果我不清除浏览器缓存,只给出“开始”和“结束”日期,则不会。所以问题不是树映射没有更新,而是浏览器缓存?