Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
How to implement Save as PNG in Vega using custom menu

I am building a data dashboard using Vega to visualize the outputs, and to accomplish that I've removed the actions dropdown and replaced it with a custom menu system. I would like to incorporate the "Save as PNG" option that exists in the original dropdown (example provided in image below) into my own menu though, since I assume the architecture for creating the image already exists, works well, and should be relatively simple to port over. But I have no idea how I might go about referencing those actions separate from the original menu.

How can I link the Save as PNG functionality to a button that exists outside of the Vega actions dropdown?

Example image of stock dropdown

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The Vega view API has metohd toImageURL() that enables users to download the chart image as PNG file.

https://vega.github.io/vega/docs/api/view/#image-export

In a dashboard, there may be multiple Vega view objects for various charts. For the dashboard menu, here is an example function in javascript with Vega view object and download filename as arguments:

function vegaDownloadChartImage(vegaView, downloadFileName){
  vegaView.toImageURL('png').then(function(url) {
    var link = document.createElement('a');
    link.setAttribute('href', url);
    link.setAttribute('target', '_blank');
    link.setAttribute('download', downloadFileName);
    link.dispatchEvent(new MouseEvent('click'));
  }).catch(function(error) { /* error handling */ });
}

Example HTML button for user to download image file (myVegaChart1.png):

  <button onclick="vegaDownloadChartImage(view_1, 'myVegaChart1')">Download PNG file</button>        
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda