jquery
  • d3.js
  • force-layout
  • 2015-06-11 11 views 1 likes 
    1

    Я работаю на поисковых узлах компоновки силы d3.js от this example fiddle.Jquery ошибка при поиске узлов в макете силы d3.js

    <script type='text/javascript' src="http://code.jquery.com/ui/1.8.3/jquery-ui.min.js"></script> 
    <script type='text/javascript' src="http://code.jquery.com/ui/1.8.3/themes/smoothness/jquery-ui.css"></script> 
    <script src="http://d3js.org/d3.v3.js"></script> 
    <style> 
    .node { 
        stroke: #fff; 
        stroke-width: 1.5px; 
    } 
    .link { 
        stroke: #999; 
        stroke-opacity: .6; 
    } 
    </style> 
    
    </head> 
    <body> 
    <div class="ui-widget"> 
        <input id="search"> 
        <button type="button" onclick="searchNode()">Search</button> 
    </div> 
    
    
    //Constants for the SVG 
    var width = 500, 
        height = 500; 
    
    //Set up the colour scale 
    var color = d3.scale.category20(); 
    
    //Set up the force layout 
    var force = d3.layout.force() 
        .charge(-120) 
        .linkDistance(30) 
        .size([width, height]); 
    
    //Append a SVG to the body of the html page. Assign this SVG as an object to svg 
    var svg = d3.select("body").append("svg") 
        .attr("width", width) 
        .attr("height", height); 
    
    //Read the data from the mis element 
    var mis = document.getElementById('mis').innerHTML; 
    graph = JSON.parse(mis); 
    
    //Creates the graph data structure out of the json data 
    force.nodes(graph.nodes) 
        .links(graph.links) 
        .start(); 
    
    //Create all the line svgs but without locations yet 
    var link = svg.selectAll(".link") 
        .data(graph.links) 
        .enter().append("line") 
        .attr("class", "link") 
        .style("stroke-width", function (d) { 
        return Math.sqrt(d.value); 
    }); 
    
    //Do the same with the circles for the nodes - no 
    var node = svg.selectAll(".node") 
        .data(graph.nodes) 
        .enter().append("circle") 
        .attr("class", "node") 
        .attr("r", 8) 
        .style("fill", function (d) { 
        return color(d.group); 
    }) 
        .call(force.drag); 
    
    
    //Now we are giving the SVGs co-ordinates - the force layout is generating the co-ordinates which this code is using to update the attributes of the SVG elements 
    force.on("tick", function() { 
        link.attr("x1", function (d) { 
         return d.source.x; 
        }) 
         .attr("y1", function (d) { 
         return d.source.y; 
        }) 
         .attr("x2", function (d) { 
         return d.target.x; 
        }) 
         .attr("y2", function (d) { 
         return d.target.y; 
        }); 
    
        node.attr("cx", function (d) { 
         return d.x; 
        }) 
         .attr("cy", function (d) { 
         return d.y; 
        }); 
    }); 
    
    
    
    var optArray = []; 
    for (var i = 0; i < graph.nodes.length - 1; i++) { 
        optArray.push(graph.nodes[i].name); 
    } 
    
    optArray = optArray.sort(); 
    
    $(function() { 
        $("#search").autocomplete({ 
         source: optArray 
        }); 
    }); 
    
    
    function searchNode() { 
    
        //find the node 
    
        var selectedVal = document.getElementById('search').value; 
        var node = svg.selectAll(".node"); 
    
        if (selectedVal == "none") { 
         node.style("stroke", "white").style("stroke-width", "1"); 
        } else { 
         var selected = node.filter(function (d, i) { 
          return d.name != selectedVal; 
         }); 
         selected.style("opacity", "0"); 
         var link = svg.selectAll(".link") 
         link.style("opacity", "0"); 
         d3.selectAll(".node, .link").transition() 
          .duration(5000) 
          .style("opacity", 1); 
    
    
        } 
    } 
    
    
    
        </script> 
    </body> 
    </html>e 
    

    Я получаю сообщение об ошибке:

    Uncaught ReferenceError: jQuery is not defined(anonymous function) @ jquery-ui.min.js:8 jquery-ui.css:13 Uncaught SyntaxError: Unexpected token . searchingforcelayout.html:1362 Uncaught ReferenceError: $ is not defined

    Я включил

    <script type='text/javascript' src="http://code.jquery.com/ui/1.8.3/jquery-ui.min.js"></script> 
    <script type='text/javascript' src="http://code.jquery.com/ui/1.8.3/themes/smoothness/jquery-ui.css"></script> 
    

    Это хорошо работает в скрипке, но не работает в моей системе. Я использую Chrome в качестве моего браузера.

    +0

    Вам нужно включить jquery - '' –

    ответ

    0

    Включенный jQuery? Убедитесь, что он включен до включения библиотеки jQuery UI JS.

    +0

    привет, как я уже говорил выше, я включил два теги сценария, </ название <сценарий SRC = "/ /code.jquery.com/jquery-1.11.3.min.js "></script> <сценарий SRC =" http://d3js.org/d3.v3.js "></script> <style>, но он не работает. – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">Uncaught ReferenceError: jQuery не определен (анонимная функция) @ jquery-ui.min.js: 8 jquery-ui.css: 13 Uncaught SyntaxError: Неожиданный токен. forceearch.html: 1349 Uncaught ReferenceError: $ не определено hi, спасибо за помощь, я вношу точные изменения и все же получаю эту ошибку в моем хроме, сафари и firefox. Наверное, я не могу понять, какую ошибку я делаю. @Ivan – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">Вы не забыли включить jquery-1.11.3.min.js перед jquery-ui.min.js? – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2100636/">amurrell</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048337"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> Смежные вопросы</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item">Нет связанных вопросов^_^</li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://ru.uwenku.com/contact">Свяжитесь с нами</a></li> <li>© 2020 RU.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>