У меня возникли проблемы с добавлением легенды диаграммы в мой график d3js. Вот мой нынешний подход:
var legend = svg.append("g")
.attr("class", "legend")
.attr("x", w - 65)
.attr("y", 25)
.attr("height", 100)
.attr("width", 100);
legend.append("rect")
.attr("x", w - 65)
.attr("y", 25)
.attr("width", 10)
.attr("height", 10)
.style("fill", function(d) { return color_hash[dataset.indexOf(d)][1] });
legend.append("text")
.attr("x", w - 65)
.attr("y", 25)
.text(function(d) { return color_hash[dataset.indexOf(d)][0] + ": " + d; });
Затем я пытаюсь создать стиль .legend
:
.legend {
padding: 5px;
font: 10px sans-serif;
background: yellow;
box-shadow: 2px 2px 1px #888;
}
Но мне не повезло.
Кто-нибудь знаком с добавлением легенд в диаграммы, способные обеспечить лучший способ сделать это? Я не нахожу много ресурсов для этого онлайн.
Вот мой весь график: http://jsbin.com/ewiwag/2/edit