Angular Highcharts:带图例的饼状图(Pie Chart with Legends)
以下是带图例的饼状图的一个示例。
配置
chart
将图表类型配置为基于“pie”。chart.type决定图表的系列类型。这里,默认值是“line”。
var series = { type: 'pie' };
plotOptions
使用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] ] }] }; }
结果