<div id="chart" style="width: 500px; display: none;">
Placeholder
</div>
<script type="module">
import vegaEmbed from 'https://cdn.jsdelivr.net/npm/vega-embed@7/+esm'
await vegaEmbed(
'#chart',
{
width: 'container',
data: {
values: [
{"category": "A", "amount": 28},
{"category": "B", "amount": 55},
],
},
mark: "bar",
encoding: {
x: {field: "category", type: "nominal"},
y: {field: "amount", type: "quantitative"},
},
},
);
setTimeout(function() {
document.querySelector("#chart").style.display = "block"
}, 500);
Bug Description
Setting the initial
displaymode tononein a container element for Vega-Embed leads to no visible rendering when the Vega-Lite spec setswidth: "container":The final
<svg>element has awidth="0"(andviewBox="0 0 0 344"). I guess that's correct in the sense that adisplay: noneelement has no width. UsinggetComputedStyleshould lead to a somewhat better result in those cases, though?Codepen: https://codepen.io/editor/lehmannro/pen/01a03034-ca12-7f36-a3ef-1982bb5c0bb9
Checklist
getComputedStyleordisplay none