最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to put text data with d3.js - Stack Overflow

programmeradmin5浏览0评论

what am I doing wrong? x.innerHTML is undefined as result.

How can I put the text, returned by d3.json in x? Thanks.

        <tr>
            <td>1</td>
            <td id = "val">0.087</td>
            <td>0.23</td>
            <td>0.3</td>
        </tr>
    </table>
    <script type="text/javascript" src=".v3.min.js" charset="utf-8">
    </script>
    <script type="text/javascript">
        var x = d3.select("#val");

        setInterval(function() {
            d3.json("./cgi-bin/script1.sh", function(error, text){
                if (error) return console.warn(error);

                console.debug(text.date);
                x.innerHTML = text.date;
            })
        }, 1000);

    </script>
</body>

what am I doing wrong? x.innerHTML is undefined as result.

How can I put the text, returned by d3.json in x? Thanks.

        <tr>
            <td>1</td>
            <td id = "val">0.087</td>
            <td>0.23</td>
            <td>0.3</td>
        </tr>
    </table>
    <script type="text/javascript" src="http://d3js/d3.v3.min.js" charset="utf-8">
    </script>
    <script type="text/javascript">
        var x = d3.select("#val");

        setInterval(function() {
            d3.json("./cgi-bin/script1.sh", function(error, text){
                if (error) return console.warn(error);

                console.debug(text.date);
                x.innerHTML = text.date;
            })
        }, 1000);

    </script>
</body>

Share Improve this question asked Aug 5, 2015 at 7:36 Иосиф СталинИосиф Сталин 1471 gold badge3 silver badges7 bronze badges 1
  • when do you access the x.InnerHTML? Perhaps you are accessing it before it gets updated? – Adam Moszczyński Commented Aug 5, 2015 at 7:40
Add a ment  | 

1 Answer 1

Reset to default 16

Your x is not a native dom element, it's a dom element wrapped by d3 and therefore does not possess the .innerHTML attribute.

Either use a d3 method to do it :

x.html(text.date)

Or get the original node and use innerHTML

x.node().innerHTML = text.date
发布评论

评论列表(0)

  1. 暂无评论