我们如何在highcharts-angular中添加图表快捷菜单?

czq61nw1  于 2022-11-10  发布在  Highcharts
关注(0)|答案(2)|浏览(170)

在我的highcharts-angular应用程序中,需要显示图表上下文菜单,如下图所示。

我已经看过了这个https://www.highcharts.com/demo/pie-basic的例子,但这整个代码在JavaScript & jQuery中。但在这里我需要在highcharts-angular中有相同的功能。
我的示例代码如下:是的。

mkshixfv

mkshixfv1#

Highcharts上下文菜单需要导入和初始化exportingexport-data模块:

import * as HighchartsExporting from "highcharts/modules/exporting";
import * as HighchartsExportData from "highcharts/modules/export-data";

HighchartsExporting(Highcharts);
HighchartsExportData(Highcharts);

您的应用程序.组件.ts:

import { Component, OnInit } from "@angular/core";
import * as Highcharts from "highcharts";
import * as HighchartsExporting from "highcharts/modules/exporting";
import * as HighchartsExportData from "highcharts/modules/export-data";

HighchartsExporting(Highcharts);
HighchartsExportData(Highcharts);

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
  Highcharts = Highcharts;
  chartOptions = {
    chart: {
      plotBackgroundColor: null,
      plotBorderWidth: null,
      plotShadow: false,
      type: "pie"
    },
    title: {
      text: "Browser market shares in January, 2018"
    },
    tooltip: {
      pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"
    },
    plotOptions: {
      pie: {
        allowPointSelect: true,
        cursor: "pointer",
        dataLabels: {
          enabled: true,
          format: "<b>{point.name}</b>: {point.percentage:.1f} %"
        },
        showInLegend: true
      }
    },
    credits: {
      enabled: false
    },
    series: [
      {
        name: "Brands",
        colorByPoint: true,
        data: [
          {
            name: "Chrome",
            y: 61.41,
            sliced: true,
            selected: true
          },
          {
            name: "Internet Explorer",
            y: 11.84
          },
          {
            name: "Firefox",
            y: 10.85
          },
          {
            name: "Edge",
            y: 4.67
          },
          {
            name: "Safari",
            y: 4.18
          },
          {
            name: "Sogou Explorer",
            y: 1.64
          },
          {
            name: "Opera",
            y: 1.6
          },
          {
            name: "QQ",
            y: 1.2
          },
          {
            name: "Other",
            y: 2.61
          }
        ]
      }
    ]
  };
  ngOnInit() {}
}

演示:https://codesandbox.io/s/2z2y2n07w0

euoag5mw

euoag5mw2#

根据this documentation in npmjs.com,应将这些行添加到相应的组件中,以便出现下载上下文按钮:

import * as Highcharts from 'highcharts';
import HC_exporting from 'highcharts/modules/exporting';

HC_exporting(Highcharts);

相关问题