Search code examples
vega-liteobservablehq

Download vega-lite chart rendered as svg in Observablehq


I'm learning Observablehq and Vega Lite. I created this observable : https://observablehq.com/@mavromatika/untitled

I don't understand why The interface won't let me download the chart, neither as SVG nor as PNG. I know it should work because both downloads are possible on the charts in the example page : https://observablehq.com/@vega/vega-lite-api (SVG only when properly rendered).

There's got to be something obvious that's escaping me.


Solution

  • It seems like it's a bug, if you change the width to >= 500px the UI buttons to save SVG/PNG appears. I'll report it on the forum

    something = {
        const plot = vl.markBar()
                      .data(data)
                      .encode(
                        vl.x().fieldN("annee"),
                        vl.y().fieldQ("valeur"),
                        vl.color().fieldN("emission")
                      )
                      .width(500)
                      .height(500)
                      .autosize({type: 'fit-x', contains: 'padding'})
    
          return plot.render({renderer: 'svg'});
    }