简体   繁体   English

HighCharts导出隐藏滚动条

[英]HighCharts Export Hide Scrollbars

How would I go about hiding enabled scrollbars on a HighChart when I use the export the chart via the export library? 通过导出库使用导出图表时,如何在HighChart上隐藏已启用的滚动条? I have tried to toggle the display of the scrollbars but it seems that when the internal code calls chart.getSVG(), any changes made to the chart outside of the HighCharts library are omitted (eg, modifying chart elements through code). 我试图切换滚动条的显示,但是似乎当内部代码调用chart.getSVG()时,在HighCharts库外部对图表进行的任何更改都将被忽略(例如,通过代码修改图表元素)。

Please see a working example here: jsfiddle 请在此处查看工作示例: jsfiddle

HTML 的HTML

<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/offline-exporting.js"></script>

<div id="container"></div>

<button id="toggleScrollbar">
  Toggle Scrollbar
</button>

JavaScript 的JavaScript

 $(function() {
  Highcharts.chart('container', {
    exporting: {
      chartOptions: { // specific options for the exported image
        plotOptions: {
          series: {
            dataLabels: {
              enabled: true
            }
          }
        }
      },
      scale: 3,
      fallbackToExportServer: false
    },

    chart: {
      type: 'bar'
    },
    title: {
      text: 'Historic World Population by Region'
    },
    subtitle: {
      text: 'Source: <a href="https://en.wikipedia.org/wiki/World_population">Wikipedia.org</a>'
    },
    xAxis: {
      categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
      title: {
        text: null
      },
      scrollbar: {
        enabled: true
      }
    },
    yAxis: {
      min: 0,
      title: {
        text: 'Population (millions)',
        align: 'high'
      },
      labels: {
        overflow: 'justify'
      }
    },
    tooltip: {
      valueSuffix: ' millions'
    },
    plotOptions: {
      bar: {
        dataLabels: {
          enabled: true
        }
      }
    },
    legend: {
      layout: 'vertical',
      align: 'right',
      verticalAlign: 'top',
      x: -40,
      y: 80,
      floating: true,
      borderWidth: 1,
      backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
      shadow: true
    },
    credits: {
      enabled: false
    },
    series: [{
      name: 'Year 1800',
      data: [107, 31, 635, 203, 2]
    }, {
      name: 'Year 1900',
      data: [133, 156, 947, 408, 6]
    }, {
      name: 'Year 2012',
      data: [1052, 954, 4250, 740, 38]
    }]

  });

  $('#toggleScrollbar').on('click', function() {
    var $scrollbar = $('#container').find('.highcharts-scrollbar');
    $scrollbar.toggle();
  });
});

As you can see, when you export the chart in any format, the scrollbar for the chart is displayed. 如您所见,以任何格式导出图表时,都会显示图表的滚动条。 However, when you toggle the scrollbar using the button below the chart and then export it, the scrollbar is still rendered in the export. 但是,当您使用图表下方的按钮切换滚动条然后将其导出时,滚动条仍会在导出中呈现。

I could not find any info on disabling scrollbars dynamically :( 我找不到有关动态禁用滚动条的任何信息:(

Note: The scrollbar needs to be enabled for use in my client's environment. 注意:需要启用滚动条才能在我的客户端环境中使用。 This was just a quick example with scrollbar enabled to demonstrate the issue. 这只是启用滚动条来演示此问题的简单示例。

You can set additional options for an exported chart in the exporting.chartOptions property - the options will be merged. 您可以在exporting.chartOptions属性中为导出的图表设置其他选项-这些选项将被合并。

exporting: {
  chartOptions: { // specific options for the exported image
    plotOptions: {
      series: {
        dataLabels: {
          enabled: true
        }
      }
    },
    xAxis: {
        scrollbar: {
        enabled: false
      }
    }
  },
  scale: 3,
  fallbackToExportServer: false
},

example: http://jsfiddle.net/gjrqyj2g/13/ 示例: http//jsfiddle.net/gjrqyj2g/13/

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

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