简体   繁体   English

如何在3D Highcharts上设置背景图像?

[英]How to set background image on 3d highcharts?

在此处输入图片说明

I'd like to set an image of a map - or, better yet, a generated map - on the xz plane of a high-charts graph. 我想在高图表图的xz平面上设置地图的图像,或者更好的是生成的地图。 Is there a way to do this with background image? 有没有办法用背景图像做到这一点? I understand you can set the color of the back, bottom, and side frame, is there any way to set images for those frames? 我知道您可以设置背面,底部和侧面框架的颜色,是否有任何方法可以设置这些框架的图像?

You can use SVG <pattern> element with <image> added inside of it, and set the chart.options3d.frame.bottom.color equal to this pattern, just like that: 您可以在其中添加<image> SVG <pattern>元素中使用,并将chart.options3d.frame.bottom.color设置为与此模式相同,如下所示:

First you need to create new pattern basing on current dimensions of mentioned frame . 首先,您需要根据上述frame当前尺寸创建新的图案。 The best place to implement it, should be the chart.events.load function: 实现它的最佳位置应该是chart.events.load函数:

chart: {
    events: {
      load() {
        var chart = this
        var frameBottomDim = chart.frameShapes.bottom.element.getBBox()
        var defs = document.querySelectorAll('defs')[0]
        var pattern = chart.renderer.createElement('pattern')
        var img = chart.renderer.createElement('image')

        pattern.attr({
          "patternUnits": "userSpaceOnUse",
          "x": frameBottomDim.x,
          "y": frameBottomDim.y,
          "width": frameBottomDim.width,
          "height": frameBottomDim.height,
          "id": "frameBg",
        })

        img.attr({
          "href": "https://static.makeuseof.com/wp-content/uploads/2010/03/clouds-1-670x335.jpg",
          "width": frameBottomDim.width,
          "height": frameBottomDim.height,
          preserveAspectRatio: 'none'
        })

        img.add(pattern)
        pattern.add(this.renderer.defs)

      }
    }
}

Then set the frame color property to url(#[pattern_name]) : 然后将框架color属性设置为url(#[pattern_name])

 options3d: {
      enabled: true,
      alpha: 10,
      beta: 20,
      depth: 400,
      frame: {
        bottom: {
          color: 'url(#frameBg)'
        }
      }
    }

Live example: https://jsfiddle.net/h8tv4xpg/ 实时示例: https//jsfiddle.net/h8tv4xpg/

Web API Reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern Web API参考: https//developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM