You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/01/05 10:38:36 UTC

[GitHub] [incubator-echarts] plainheart commented on issue #13947: 象形图实例spirit,设置symbol为外网图片,显示没问题,但是'保存为图片'有跨域问题!

plainheart commented on issue #13947:
URL: https://github.com/apache/incubator-echarts/issues/13947#issuecomment-754554933


   `symbol` 暂时还不支持设置 `Image` 对象,目前看来只能是尽量别引用第三方非跨域的图片。
   如果是设置 `backgroundColor` 和 `color` 这些,现在是支持传入 `Image` 对象,
   
   ```js
   var img = new Image()
   img.src = 'https://avatars0.githubusercontent.com/u/27989856';
   // 该图片服务器响应了 Access-Control-Allow-Origin: *,因此我们可以通过设置跨域属性来使 canvas 可以正常导出。
   img.crossOrigin = 'anonymous';
   img.onload = function () {
       myChart.setOption({
           backgroundColor: {
               image: img,
               repeat: 'repeat'
           }
       })
   }
   ```
   
   当然只指定 `crossOrigin` 并不足够,还需服务端配合响应 `Access-Control-Allow-Origin: *` 字段,如果服务器不允许跨域,那么设置这个字段也无法正常导出。


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org