Highcharts Backgroundimage for bar graph

守給你的承諾、 提交于 2019-12-24 00:59:45

问题


I want to add a background image to a bar chart using Highcharts and display it in a UIWebView.

So far I've been using this little plugin, which is working fine in latest Chrome. However, as soon as I load this into my UIWebView, the image is not displayed. I think this is related to the fact that iOS might not be able to parse the correct path for the image file?

Is there another (simpler) way to just add a background-image to a bar chart?

In my Highcharts data series

color: {
   pattern: 'static/img/theimage.png',
   width: 160,
   height: 500
}

The plugin

/**
 * Highcharts pattern fill plugin
 */
(function() {
    var idCounter = 0,
        base = Highcharts.Renderer.prototype.color;

    Highcharts.Renderer.prototype.color = function(color, elem, prop) {
        if (color && color.pattern && prop === 'fill') {
            // SVG renderer
            if (this.box.tagName == 'svg') {
                var id = 'highcharts-pattern-'+ idCounter++;
                var pattern = this.createElement('pattern')
                        .attr({
                            id: id,
                            patternUnits: 'userSpaceOnUse',
                            width: color.width,
                            height: color.height
                        })
                        .add(this.defs),
                    image = this.image(
                        color.pattern, 0, 0, color.width, color.height
                    )
                    .add(pattern);
                return 'url(' + this.url + '#' + id + ')';

            // VML renderer
            } else {
                var markup = ['<', prop, ' type="tile" src="', color.pattern, '" />'];
                elem.appendChild(
                    document.createElement(this.prepVML(markup))
                );                
            }

        } else {
            return base.apply(this, arguments);
        }
    };    
})();

回答1:


I had a similar problem in that my iPad wasn't showing up my gradient background.

I solved this in the end by putting backgroundColor: null, in my JS and using a CSS3 gradient on the ID and declaring the height of the DIV. This would most probably work with a background image as well.



来源:https://stackoverflow.com/questions/10982137/highcharts-backgroundimage-for-bar-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!