Highchart with scaled images in column bars?

2020-03-30 04:29发布

How can i add images to the bar columns that scale correctly to the bar heights.

see jsfiddle example below, im trying to do a chart that compares heights using a Skyscraper image as the background for the bar columns, however the background image seems to loop/tile somewhat randomly, how can i fix this.

thanks

        color: {
           pattern: 'http://www.aperfectworld.org/clipart/buildings/buildings08g.gif',
           width: '100%',
           height: '100%'
        }

http://jsfiddle.net/2BqSY/4/

1条回答
神经病院院长
2楼-- · 2020-03-30 05:05

I think it may be not possible using patterns, but you can add some images using renderer: http://jsfiddle.net/YZkPX/

    chart: {
        renderTo: 'container',
        type: 'column',
        events: {
            load: function () {
                var chart = this,
                    d = chart.series[0].data;

                for (var i = 0, len = d.length; i < len; i++) {
                    var p = d[i],
                        x = chart.plotLeft + p.plotX - p.pointWidth / 2,
                        y = chart.plotTop + p.plotY,
                        w = p.pointWidth,
                        h = p.graphic.height;
                    chart.renderer.image('http://www.aperfectworld.org/clipart/buildings/buildings08g.gif', x, y, w, h).add();

                }

            }
        }
    },

Now you need to recalculate x/y/w/h when series is redraw (zoom/show/hide etc.)

查看更多
登录 后发表回答