0

我正在使用 amcharts4 构建热图,然后通过dom2img将其转换为图像。一切都很好,地图本身也被渲染了,但图例没有被 dom2img 捕获。图例本身是一个 svg 元素。

我想也许它与渐变有关,因为这是唯一的元素。

svg 元素:

<g fill-opacity="1" fill="url(&quot;http://localhost:4200/campaigns/pptx/2#gradient-id-257&quot;)" style="pointer-events: none;"><path d="M0,0 L455,0 a0,0 0 0 1 0,0 L455,20 a0,0 0 0 1 -0,0 L0,20 a0,0 0 0 1 -0,-0 L0,0 a0,0 0 0 1 0,-0 Z"></path></g> 

Dom2img 应该渲染图例元素。

4

1 回答 1

1

改用 amCharts 内置导出功能:https ://www.amcharts.com/docs/v4/concepts/exporting/

// First enable export
chart.exporting.menu = new am4core.ExportMenu();

chart.exporting.extraSprites.push({
    "sprite": legendContainer,
    "position": "bottom",
    "marginTop": 20
});

// Then you can get the Base64 image
var imgData = chart.exporting.getImage("png");

您还可以使用extraSprites如上所示的图例。阅读有关在 export 中包含外部图例的更多信息。

于 2019-04-23T04:54:59.450 回答