Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put text data with d3.js

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.org/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>

like image 719
Иосиф Сталин Avatar asked Aug 05 '15 07:08

Иосиф Сталин


1 Answers

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
like image 73
rlink Avatar answered Oct 13 '22 21:10

rlink