帶有堆疊百分比的欄形圖



以下是一個帶有堆疊百分比的欄形圖示例。

我們在 Highcharts 配置語法 章節中已經瞭解了用於繪製圖表的配置。現在讓我們來看一些其他配置,以及如何在 plotoptions 中新增堆疊屬性。

以下是帶有堆疊百分比的欄形圖的示例。

plotOptions

plotOptions 是對每種序列型別配置物件的包裝物件。還可以針對序列陣列中給出的每個序列項覆寫每個序列的配置物件。這將把每個序列的值彼此疊放。這將把每個序列的值彼此疊放。

使用 plotOptions.column.stacking 將圖表的堆疊配置為“percent”。可能的值有 null,它會停用堆疊,“normal”會按值堆疊,“percent”會按百分比堆疊圖表。

var plotOptions = {
   series: {
      stacking: 'percent'
   }
};

示例

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: {
         type: 'column'
      },
      title: {
         text: 'Historic World Population by Region'
      },
      subtitle : {
         text: 'Source: Wikipedia.org'  
      },
      legend : {
         layout: 'vertical',
         align: 'left',
         verticalAlign: 'top',
         x: 250,
         y: 100,
         floating: true,
         borderWidth: 1,
        
         backgroundColor: (
            (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 
               '#FFFFFF'), shadow: true
       },
       xAxis:{
         categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'], title: {
            text: null
         } 
      },
      yAxis : {
         min: 0,
         title: {
            text: 'Population (millions)', align: 'high'
         },
         labels: {
            overflow: 'justify'
         }
      },
      tooltip : {
         valueSuffix: ' millions'
      },
      plotOptions : {
         column: {
            dataLabels: {
               enabled: true
            }
         },
         series: {
            stacking: 'percent'
         }
      },
      credits:{
         enabled: false
      },
      series: [
         {
            name: 'Year 1800',
            data: [107, 31, 635, 203, 2]
         }, 
         {
            name: 'Year 1900',
            data: [133, 156, 947, 408, 6]
         }, 
         {
            name: 'Year 2008',
            data: [973, 914, 4054, 732, 34]      
         }
      ]
   };
}

結果

驗證結果。

Stacked Column Chart with percentages
angular_highcharts_column_charts.htm
廣告
© . All rights reserved.