简体   繁体   中英

D3 not displayed within jupyter notebook

I am writing this html/javascript/d3 code within jupyter notebook, which runs without any error but it doesn't display anything. Ideally it should display two circles, one with color blue and other with color green. What could be an issue?

HTML('<script src="http://d3js.org/d3.v3.min.js"></script>')

HTML('''
<div class="legend">Sample</div>   
<div id="sample"></div>
 <script type="text/javascript">

 var svg=d3.select("#sample").append("svg").attr("width",500).attr("height",200);
 var dataset = [
{
    x: 10,
    y: 10,
    r: 2,
    text:"a",
    color:"blue"
},
{
    x: 20,
    y: 10,
    r: 2,
    text:"b",
    color:"green"
}];
 svg.selectAll("circle")
 .data(dataset)
 .enter()
 .append("circle")
 .attr("cx",function(d){return d.x;})
 .attr("cy",function(d){return d.y;})
 .attr("r",function(d){return d.r;})
 .attr("fill",function(d){return d.color;})
 .text(function(d){return d.text;});

 ''')

可能的问题:您忘记关闭<script type="text/javascript">谢谢!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM