Estoy tratando de obtener una imagen SVG de un enlace. Al obtener una imagen svg de https://www.coingecko.com/coins/976/sparkline , funciona perfectamente, la imagen svg se muestra. Cuando intento obtenerlo de https://www.coinparticle.com/sparkline/bitcoin , no aparece.
Creo que esto tiene algo que ver con ciertas etiquetas utilizadas en el código HTML.
<html> <head></head> <body></body> </html>¿Cómo puedo ajustar el código en coinparticle para obtener la imagen svg (tengo acceso al servidor de coinparticle)?
1 <img class="1" src="https://www.coingecko.com/coins/7598/sparkline"> 2 <img class="2" src="https://www.coinparticle.com/sparkline/bitcoin">Código en coinpartícula:
<html></html> <script> const height = 50; //the number of pixels high the chart is to be const points = [[1631264425426,46187.88927989531],[1631268120084,46346.477413458255],[1631271810755,46460.52411265284],[1631275266134,46472.58450929567]] const len = points.length; let minx = points[0][0] let maxx = points[0][0]; let miny = points[0][1]; let maxy = points[0][1]; points.forEach( (point) => { minx = (point[0] < minx) ? point[0] : minx; maxx = (point[0] > maxx) ? point[0] : maxx; miny = (point[1] < miny) ? point[1] : miny; maxy = (point[1] > maxy) ? point[1] : maxy; } ); function setup() { const width = 135; let svg = '<svg width="' + width + '" height="' + (height+4) + '" viewBox="0 0 135 54"' + '"xmlns="http://www.w3.org/2000/svg"' + '"xmlns:xlink="http://www.w3.org/1999/xlink"' + '><polyline points="'; points.forEach( (point) => { svg = svg + ((point[0] - minx) / (maxx - minx)) * width + ',' + (height - ((point[1] - miny) / (maxy - miny)) * height + 2) + ' '; }); svg = svg + '" stroke-linejoin="round" style="fill: transparent; stroke:green; stroke-width:2" /></svg>'; document.body.insertAdjacentHTML('beforebegin', svg) } setup(); </script>Si no desea cambiar su código en coinparticle, puede crear un pequeño iframe para cargar el contenido.
1 <img class="1" src="https://www.coingecko.com/coins/7598/sparkline"> 2 <iframe src="https://www.coinparticle.com/sparkline/bitcoin" width="135" height="54" scrolling="no" style="border:0;overflow:hidden;"></iframe>