简体   繁体   English

设置自定义图像从底部到顶部条形图的内部条形(使用高图)?

[英]Set custom image from bottom to top inside bars of bar graph (using highcharts)?

So I have added custom image inside bars of bar graph (chart library highcharts).所以我在条形图(图表库 highcharts)中添加了自定义图像。 But the images are filled from top to bottom so the image at the bottom is cut but the x-axis (image attached below).但是图像是从上到下填充的,所以底部的图像被切割但 x 轴(下图)。

bar graph with custom image带有自定义图像的条形图

Code I have written till now我写到现在的代码

var redrawEnabled = true,
        ctr = 0;
        Highcharts.chart('container', {
            chart: {
                type: 'column',
                events: {
                    load: function(){
                        if(this.options.chart.type == 'column'){
                            this.xAxis[0].update({
                            reversed: false
                        });
                        }
                    },
                render: function() {
                    if (redrawEnabled) {
                        redrawEnabled = false;
                        var chart = this,
                            renderer = chart.renderer;
                            
                            chart.series[0].points.forEach(function(p) {
                            
                            var widthRatio = p.shapeArgs.width / p.shapeArgs.height
                            id = 'pattern-' + p.index + '-' + ctr;

                            var pattern = renderer.createElement('pattern').add(renderer.defs).attr({
                            width: 1,
                            height: widthRatio,
                            id: id,
                            patternContentUnits: 'objectBoundingBox'
                            });
                            renderer.image('coin6.png', 0, 0, 1, widthRatio).attr({}).add(pattern);

                            p.update({
                            color: 'url(#' + id + ')'
                            }, false);
                        });

                        ctr++;
                        chart.redraw();
                        redrawEnabled = true;
                    }
                }
            },

            },
            title: {
                text: null
            },
            legend:{ enabled:false },
            
            xAxis: {
                labels: {
                style: {
                        color: 'red',
                        fontSize:'10px'
                    }
                },
                categories: [
                'Jan',
                'Feb',
                'Mar',
                'Apr',
                'May',
                'Jun',
                'Jul',
                'Aug',
                'Sep',
                'Oct',
                'Nov',
                'Dec'
                ],
                crosshair: false,
            },
            yAxis: {
                min: 0,
                tickLength: 0,
                visible: false,
            },
            plotOptions: {
                bar: {
                    stacking: 'normal',
                },
                
            },
            series: [{
                pointWidth: 30,
                data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 144.0, 176.0, 135.6, 148.5,]
            }]
            });

1st:- So I want start the image from the bottom so that it looks similar at bottom.第一个:- 所以我想从底部开始图像,使其在底部看起来相似。 so I want the image pattern flow from bottom to top.所以我希望图像模式从下到上流动。 2nd:- Can I apply padding and margin to the image pattern so that I can stack the coin images properly 2nd:- 我可以对图像图案应用填充和边距,以便我可以正确堆叠硬币图像

I want to achieve the stack of coin as image attached.我想实现硬币堆栈作为附加的图像。 final result I want to achieve我想要达到的最终结果

You can use the xAxis.offset feature to increase this space.您可以使用xAxis.offset功能来增加此空间。

   xAxis: {
     labels: {
       style: {
         color: 'red',
         fontSize: '10px'
       }
     },
         offset: 50,
     categories: [
       'Jan',
       'Feb',
       'Mar',
       'Apr',
       'May',
       'Jun',
       'Jul',
       'Aug',
       'Sep',
       'Oct',
       'Nov',
       'Dec'
     ],
     crosshair: false,
   },

Demo: https://jsfiddle.net/BlackLabel/0wqnbtdz/演示: https://jsfiddle.net/BlackLabel/0wqnbtdz/

API: https://api.highcharts.com/highcharts/xAxis.offset API: https://api.highcharts.com/highcharts/xAxis.offset

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

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