I am trying to place a drop-down list (with select
and option
) within a div
and an SVG using d3.js, but it does not work and the select
is not seen. I do not know if they are the properties or the reason why it happens. How can I do it?
This is the code I'm using:
Note: the code comes from a question that was previously deleted and is also available in this JSFiddle .
var data = [
{"id":1,"text":"LAND1"},
{"id":2,"text":"LAND2"},
{"id":1,"text":"LAND3"}
];
var vis = d3.select(".dashboard")
.select("#sowing")
.append("div")
.append("svg")
.attr("id", "chartID")
.attr("class", "boxing")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 540 250")
.append("g")
.attr("transform", "translate(" + 550 / 2 + "," + 300 / 2 + ")");
var select = vis.append('select')
.attr("name", "dept-list")
.attr("class", "form-control");
var options = select.selectAll('option')
.data(data)
.enter()
.append('option')
.text(function(d) {
return d.text;
})
.attr("value", function(d) {
return d.id;
});
#chartID {
border: 1px solid #D4D4D4;
background-color: #FFFFFF;
border-radius: 2px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<section class="content">
<div class="col-lg-12">
<div class="dashboard">
<div id="sowing"></div>
</div>
</div>
</section>