How can we add chart context menu in highcharts-angular?

你离开我真会死。 提交于 2019-12-13 03:47:48

问题


Can someone please help me in this, actually in my highcharts-angular application need to be display chart context menu as show in below image.

And I have gone through this https://www.highcharts.com/demo/pie-basic example but this whole code in javascript & Jquery. But here I need same functionality in highcharts-angular. Please find my sample code here https://stackblitz.com/edit/angular-s6h17i & please share your suggestions. Thanks in advance.


回答1:


Highcharts context menu requires to import and initialize exporting and export-data modules:

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

HighchartsExporting(Highcharts);
HighchartsExportData(Highcharts);

Your app.component.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() {}
}

Demo: https://codesandbox.io/s/2z2y2n07w0



来源:https://stackoverflow.com/questions/54404116/how-can-we-add-chart-context-menu-in-highcharts-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!