Simple D3 demo not working with altered structure

前端 未结 1 426
面向向阳花
面向向阳花 2021-01-27 05:32

I was following the official tutorial. Since the structure was pretty rudimentary I decided to do a cleaner one:



&         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 05:59

    Your script is on the head, and it's being parsed before the div with a class "chart" being generated .

    Just move all your script to the end of the body, after the div you are selecting:

    .chart div {
            font: 10px sans-serif;
            background-color: steelblue;
            text-align: right;
            padding: 3px;
            margin: 1px;
            color: white;
        }
    
    
    

    If you want to keep the script in the head, for whatever reason, just change d3.select(".chart") for d3.select("body"):

    div {
            font: 10px sans-serif;
            background-color: steelblue;
            text-align: right;
            padding: 3px;
            margin: 1px;
            color: white;
        }
    
    D3
    
    
    
    
    
    

    0 讨论(0)
提交回复
热议问题