Angular Highcharts - 帶圖例的餅狀圖



以下是帶圖例的餅狀圖示例。

我們已經在 Highcharts 配置語法 章節中瞭解了用於繪製圖表時的配置。

下面給出了帶圖例的餅狀圖示例。

配置

現在讓我們瞭解一下所採取的其他配置/步驟。

圖表

設定圖表型別基於“餅圖”。chart.type 確定圖表的序列型別。此處,預設值為“line”。

var series = {
   type: 'pie'
};

繪圖選項

使用 plotOptions.pie.showInLegend 屬性配置繪圖選項,以便在餅狀圖中顯示圖例。

plotOptions : {
   pie: {
      allowPointSelect: true,
      cursor: 'pointer',
      dataLabels: {
         enabled: false           
      },
      showInLegend: true
   }
}

示例

app.component.ts

import { Component } from '@angular/core';
import * as Highcharts from 'highcharts';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
   highcharts = Highcharts;
   chartOptions = {   
      chart : {
         plotBorderWidth: null,
         plotShadow: false
      },
      title : {
         text: 'Browser market shares at a specific website, 2014'   
      },
      tooltip : {
         pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
      },
      plotOptions : {
         pie: {
            allowPointSelect: true,
            cursor: 'pointer',
      
            dataLabels: {
               enabled: false           
            },
      
            showInLegend: true
         }
      },
      series : [{
         type: 'pie',
         name: 'Browser share',
         data: [
            ['Firefox',   45.0],
            ['IE',       26.8],
            {
               name: 'Chrome',
               y: 12.8,
               sliced: true,
               selected: true
            },
            ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',      0.7]
         ]
      }]
   };
}

結果

驗證結果。

Pie Chart with Legends
angular_highcharts_pie_charts.htm
廣告
© . All rights reserved.