【发布时间】:2019-11-30 14:25:41
【问题描述】:
我正在使用 c3 图表。我有一个使用canvg下载它的按钮。当点击图例时,我也有它切换栏。下载有效,切换也有效。
下载中唯一的问题是,我要么总是显示图例(即使它们对应的条没有显示),要么一旦我切换图例,图例就再也不会出现在下载中(尽管它确实在图表本身上)。
我希望图例仅在其相应的条实际显示时才出现。如果正在显示它们的栏,我也不希望隐藏传说。 (Legend Shown Bar Shown 种关系)
我过去遇到过 IE 问题,所以在 https://github.com/c3js/c3/issues/2528 之后显示为“阻止”。
var string = ".c3-legend-item-hidden";//hides legends that are unselected in the download. Will KEEP them hidden even if retoggled :(
d3.selectAll(string).each(function() {
var element = this;
var computedStyle = getComputedStyle(element, null);
for (var i = 0; i < computedStyle.length; i++) {
var property = computedStyle.item(i);
element.style[property] = computedStyle.getPropertyValue(property);
}
});
//removing this section makes all legends appear permanently regardless of whether the bar does
预期:a graph that has the correct bars and legends shown in the downloads
实际:
(带代码段)hidden legends that do not reappear when needed
(无代码段)legends that are never hidden
更新:澄清一下,这在将图形转换为下载的 svg 文件(添加 xmlns 等)时有效,只是在使用 canvg 并下载到 png 文件时无效(这是我需要它做的)。
【问题讨论】:
标签: javascript d3.js bar-chart legend c3.js