【问题标题】:"viewFullscreen" menu item is not showing in the context menu of highcharts 6.2.0“viewFullscreen”菜单项未显示在 highcharts 6.2.0 的上下文菜单中
【发布时间】:2019-04-05 10:04:33
【问题描述】:

我有一个当前显示在 bootstrap 4 卡中的 highchart 折线图。 我希望它全屏显示,我目前知道 highchart 6.2.0 具有启用导出文件的选项,以便我可以使用导出上下文菜单。所以,我启用了它们,但导出上下文菜单中没有显示“showFullscreen”选项。

我导入了 highchart 并将模块导出到组件。 在文档 highchart 中,家伙说我必须将 viewFullscreen 作为字符串包含到 menuItems 数组中。我也这样做了。但没有任何效果。

import { chart } from 'highcharts';
import * as Highcharts from 'highcharts/highcharts';
import * as HighchartsMore from 'highcharts/highcharts-more';
import * as HighchartsSolidGauge from 'highcharts/modules/solid-gauge';
import * as HighChartExport from 'highcharts/modules/exporting';


HighchartsMore(Highcharts);
HighchartsSolidGauge(Highcharts);
HighChartExport(Highcharts);


@Component({
  selector: 'app-line-chart',
  templateUrl: './line-chart.component.html',
  styleUrls: ['./line-chart.component.css']
})
export class LineChartComponent implements OnInit, OnChanges {

  @ViewChild('chartTarget') chartTarget: ElementRef;
  @Input() data;
  @Input() lineColor;
  options: any;
  chart: Highcharts.ChartObject;

  constructor() { }

  ngOnInit() {
    this.drawLineChart();
  }

  ngOnChanges(changes: SimpleChanges) {
    if (this.chart && changes['data']) {
      this.drawLineChart();
    }
  }

  drawLineChart() {
    this.options = {
      chart: {
        scrollablePlotArea: {
          minWidth: 700
        },
        height: 230,
        zoomType: 'x'
      },
      title: {
        text: ''
      },
      credits: {
        enabled: false
      },
      xAxis: {
        gridLineWidth: 1,
        /*tickInterval: 7 * 24 * 3600 * 1000, // one week
        tickWidth: 0,*/
        labels: {
          align: 'left',
          x: 3,
          y: -3,
          enabled: false
        }
      },
      yAxis: [{ // left y axis
        title: {
          text: null
        },
        padding: 3,
        showFirstLabel: false,
        gridLineWidth: 1,
        /*labels: {
          align: 'left',
          x: -10
        }*/
      }],
      colors: this.lineColor,
      legend: {
        align: 'left',
        verticalAlign: 'bottom',
        borderWidth: 0
      },
      tooltip: {
        shared: true,
        crosshairs: true,
        headerFormat: ''
      },
      exporting: {
        enabled: true,
        menuItemDefinitions: {
          // Custom definition
        },
        buttons: {
          contextButton: {
            menuItems: ['viewFullscreen']
          }
        }
      },
      plotOptions: {
        series: {
          cursor: 'pointer',
          marker: {
            enabled: false
          }
        }
      },
      series: this.data
    };
    this.chart = chart(this.chartTarget.nativeElement, this.options as any);
  }

}

我点击了这个链接https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/exporting/menuitemdefinitions/

但是当我点击那个汉堡包图标时,除了“viewFullscreen”选项之外的所有其他选项都不起作用。

【问题讨论】:

    标签: highcharts angular7


    【解决方案1】:

    要将自定义按钮添加到上下文菜单,您必须将其添加到 exporting.menuItemDefinitionsexporting.buttons.contextButton.menuItems 数组。请注意,全屏需要加载一个额外的模块:modules/full-screen

    代码:

    Highcharts.chart('container', {
      exporting: {
        menuItemDefinitions: {
          fullscreen: {
            onclick: function() {
              Highcharts.FullScreen.prototype.init(this.renderTo);
            },
            text: 'Full screen'
          }
        },
        buttons: {
          contextButton: {
            menuItems: ['downloadPNG', 'downloadSVG', 'separator', 'fullscreen']
          }
        }
      },
      series: [{
        data: [
          43934,
          52503,
          57177,
          69658,
          97031,
          119931,
          137133,
          154175
        ]
      }],
    });
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <script src="https://code.highcharts.com/modules/full-screen.js"></script>
    <div id="container"></div>

    演示:

    Angular 演示:

    API 参考:

    【讨论】:

    • 嗨,我使用 npm 安装了 highcharts,在我的节点文件夹中,highcharts/modules 文件夹中没有全屏模块。
    • 嗨@Nadee,你确定你已经安装了Highcharts 7 或更新版本吗?请注意,此模块在以前的版本中不可用。
    • 其实这是我在主题中的问题,我想知道Highchart 6.2.0版本中是否有任何选项。
    • 哦,对不起,我错过了。当然,您可以手动加载此模块并将其与版本 6.2.0 一起使用。检查这个例子:stackblitz.com/edit/angular-qpxfjg,api:github.com/highcharts/highcharts-angular#to-load-a-wrapper
    • 谢谢!但是当我单击它时,全屏选项不起作用。 stackblitz.com/edit/angular-qpxfjg 也一样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    相关资源
    最近更新 更多