如何在highcharts中调整自定义按钮的宽度和高度

问题描述 投票:1回答:1

我尝试在highcharts中调整自定义按钮的宽度和高度,但是我找不到任何关于此的演示或教程。

http://jsfiddle.net/Murali_Kaliappan/2F4pJ/1029/是我的小提琴

   $(function () {
      var chart = new Highcharts.Chart({

      chart: {
          renderTo: 'container'
      },       

      xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
      },

      series: [{
         data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
      }],

      exporting: {
          buttons: {
              customButton: {
                  x: -62,
                  onclick: function () {
                      alert('Clicked');
                  },
                  symbol: 'url(https://png.icons8.com/metro/1600/expand.png)',
                  height:18,
                  width:18
              }
           }
       }
   });
});
highcharts highstock
1个回答
2
投票

customButton.symbol应该与SVG对象一起使用 - 这就是heightwidth等配置选项不起作用的原因。

您可以使用Highcharts defs为按钮定义图像背景:

JS:

defs: {
  custombtnbg: {
    tagName: 'pattern',
    id: 'custom-btn-bg',
    x: 0,
    y: 0,
    width: 24,
    height: 24,
    children: [{
      tagName: 'image',
      width: 24,
      height: 24,
      href: 'https://png.icons8.com/metro/1600/expand.png'
    }]
  }
},

(...)

exporting: {
  buttons: {
    customButton: {
      x: -62,
      id: 'btn',
      onclick: function() {
        alert('Clicked');
      },
      text: '',
      className: 'custom-btn',
      theme: {
        'stroke-width': 0
      }
    }
  }
}

CSS:

@import 'https://code.highcharts.com/css/highcharts.css';

.custom-btn  {
   fill: url(#custom-btn-bg);
}

现场演示:http://jsfiddle.net/BlackLabel/u4Lx71by/


关于defs的文章:https://www.highcharts.com/docs/chart-design-and-style/gradients-shadows-and-patterns

© www.soinside.com 2019 - 2024. All rights reserved.