How to place text data using d3.js

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

How can I put the text returned by d3.json into x? Thank.

        <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>

      

+3


source to share


1 answer


Your x is not a native dom element, it is a d3-wrapped dom element and therefore does not have the .innerHTML attribute.

To do this, use the d3 method:

x.html(text.date)

      



Or get the original node and use innerHTML

x.node().innerHTML = text.date

      

+7


source







All Articles