一、 使用npm安裝angular2-highchartshtml
npm install angular2-highcharts --save
二、主模塊中引入 app.module.tsweb
import {ChartModule} from "angular2-highcharts"; ... imports: [ ChartModule ] ...
三、組件中定義圖標配置數據,可在highcharts官網查看配置 app.component.tssql
import {Component} from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html' }) export class AppComponent { options:Object; constructor() { this.options = { chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, type: 'pie' }, 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: true, format: '<b>{point.name}</b>: {point.percentage:.1f} %' } } }, series: [{ name: 'Brands', data: [ { name: 'Microsoft Internet Explorer', y: 56.33 }, { name: 'Chrome', y: 24.03 }, { name: 'Firefox', y: 10.38 }, { name: 'Safari', y: 4.77 }, { name: 'Opera', y: 0.91 }, { name: 'Proprietary or Undetectable', y: 0.2 } ] }] } } }
四、模板中加載圖像npm
<chart [options]="options"></chart>轉自:https://segmentfault.com/a/1190000007957170