向下钻取 (Highcharts) 在 Angular 5 中不起作用
Drill Down (Highcharts) not working in Angular 5
# 尝试了导入模块的新方法。 (app.module.ts)。在 app.module 中导入了更多模块。在组件中也有 json structre with drilldown 。仍然无法在页面上呈现
" import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import more from 'highcharts/highcharts-more.src';
import exporting from 'highcharts/modules/exporting.src';"
## Refer : https://github.com/manhar-developer/angularwidCharts
----------------------------------------------------------------------
### - Component Code :
import { Component, OnInit } from '@angular/core';
import { Chart } from 'angular-highcharts';
declare var require: any;
const Highcharts = require('highcharts');
export class LineChartComponent implements OnInit {
constructor() { }
chart1 = new Chart({
// Created pie chart using Highchart
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents using Pie chart'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
// 能够使用系列并在渲染时工作正常,但在单击时,钻取//向下不起作用
series: [{
name: 'Operating Systems',
data: [
{
name: 'Windows',
y: 88.19,
drilldown: 'windows-versions'
},
['MacOSX', 9.22],
['Linux', 1.58],
['Others', 1.01]
]
}],
drilldown: {
series: [{
name: 'Windows versions',
id: 'windows-versions',
data: [
['Win 7', 55.03],
['Win XP', 15.83],
['Win Vista', 3.59],
['Win 8', 7.56],
['Win 8.1', 6.18]
]
}]
}
});
-------------------------
在本节中导入了 chartModule、Highcharts_modules 和更多模块
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {ChartModule , HIGHCHARTS_MODULES} from 'angular-highcharts';
import more from 'highcharts/highcharts-more.src';
import exporting from 'highcharts/modules/exporting.src.js';
import { AppComponent } from './app.component';
import { LineChartComponent } from './components/line-chart/line-chart.component';
export function highchartsModules() {
// apply Highcharts Modules to this array
return [ more,exporting ];
}
@NgModule({
declarations: [
AppComponent,
LineChartComponent
],
imports: [
BrowserModule,ChartModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
使用官方npm highcharts
stackblitz 演示
app.component.ts低于
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule, OnInit, ViewChild, ElementRef, VERSION } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Component } from '@angular/core';
import * as Highcharts from 'highcharts';
import Drilldown from 'highcharts/modules/drilldown';
Drilldown(Highcharts);
// Load the exporting module.
import Exporting from 'highcharts/modules/exporting';
// Initialize exporting module.
Exporting(Highcharts);
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
name = `Angular! v${VERSION.full}`;
@ViewChild("container", { read: ElementRef }) container: ElementRef;
constructor() {
}
ngOnInit() {
Highcharts.chart(this.container.nativeElement, {
// Created pie chart using Highchart
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents using Pie chart'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
},
series: [{
name: 'Operating Systems',
data: [
{
name: 'Windows',
y: 88.19,
drilldown: 'windows-versions'
},
['MacOSX', 9.22],
['Linux', 1.58],
['Others', 1.01]
]
}],
drilldown: {
series: [{
name: 'Windows versions',
id: 'windows-versions',
data: [
['Win 7', 55.03],
['Win XP', 15.83],
['Win Vista', 3.59],
['Win 8', 7.56],
['Win 8.1', 6.18]
]
}]
}
})
}
}
**Tried following changes in
> app.module.ts
and its working fine !!**
import drilldown dependency as :
**import * as drilldown from 'highcharts/modules/drilldown.src.js'**
use providers in NgModule as :
providers: [
{provide: HIGHCHARTS_MODULES,
useFactory: () => [ drilldown]
}]
在您的 app.module.ts
中导入 angular-charts 和 drilldown 如下!
import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import * as drilldown from 'highcharts/modules/drilldown.src';
imports: [ChartModule]
providers: [
{ provide: HIGHCHARTS_MODULES, useFactory: () => [more, exporting, drilldown] }
]
在您的 component.ts 文件中以与您相同的方式初始化图表。
如果它抛出错误 Property 'type' is missing in type '{ name: string; data: ((string | number)[] | { name: string; y: number; drilldown: string; })[]; }' but required in type
然后添加类型:未定义到对象。它会按预期工作。
# 尝试了导入模块的新方法。 (app.module.ts)。在 app.module 中导入了更多模块。在组件中也有 json structre with drilldown 。仍然无法在页面上呈现
" import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import more from 'highcharts/highcharts-more.src';
import exporting from 'highcharts/modules/exporting.src';"
## Refer : https://github.com/manhar-developer/angularwidCharts
----------------------------------------------------------------------
### - Component Code :
import { Component, OnInit } from '@angular/core';
import { Chart } from 'angular-highcharts';
declare var require: any;
const Highcharts = require('highcharts');
export class LineChartComponent implements OnInit {
constructor() { }
chart1 = new Chart({
// Created pie chart using Highchart
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents using Pie chart'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
// 能够使用系列并在渲染时工作正常,但在单击时,钻取//向下不起作用
series: [{
name: 'Operating Systems',
data: [
{
name: 'Windows',
y: 88.19,
drilldown: 'windows-versions'
},
['MacOSX', 9.22],
['Linux', 1.58],
['Others', 1.01]
]
}],
drilldown: {
series: [{
name: 'Windows versions',
id: 'windows-versions',
data: [
['Win 7', 55.03],
['Win XP', 15.83],
['Win Vista', 3.59],
['Win 8', 7.56],
['Win 8.1', 6.18]
]
}]
}
});
-------------------------
在本节中导入了 chartModule、Highcharts_modules 和更多模块 app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {ChartModule , HIGHCHARTS_MODULES} from 'angular-highcharts';
import more from 'highcharts/highcharts-more.src';
import exporting from 'highcharts/modules/exporting.src.js';
import { AppComponent } from './app.component';
import { LineChartComponent } from './components/line-chart/line-chart.component';
export function highchartsModules() {
// apply Highcharts Modules to this array
return [ more,exporting ];
}
@NgModule({
declarations: [
AppComponent,
LineChartComponent
],
imports: [
BrowserModule,ChartModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
使用官方npm highcharts
stackblitz 演示
app.component.ts低于
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule, OnInit, ViewChild, ElementRef, VERSION } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Component } from '@angular/core';
import * as Highcharts from 'highcharts';
import Drilldown from 'highcharts/modules/drilldown';
Drilldown(Highcharts);
// Load the exporting module.
import Exporting from 'highcharts/modules/exporting';
// Initialize exporting module.
Exporting(Highcharts);
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
name = `Angular! v${VERSION.full}`;
@ViewChild("container", { read: ElementRef }) container: ElementRef;
constructor() {
}
ngOnInit() {
Highcharts.chart(this.container.nativeElement, {
// Created pie chart using Highchart
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents using Pie chart'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
},
series: [{
name: 'Operating Systems',
data: [
{
name: 'Windows',
y: 88.19,
drilldown: 'windows-versions'
},
['MacOSX', 9.22],
['Linux', 1.58],
['Others', 1.01]
]
}],
drilldown: {
series: [{
name: 'Windows versions',
id: 'windows-versions',
data: [
['Win 7', 55.03],
['Win XP', 15.83],
['Win Vista', 3.59],
['Win 8', 7.56],
['Win 8.1', 6.18]
]
}]
}
})
}
}
**Tried following changes in
> app.module.ts
and its working fine !!**
import drilldown dependency as :
**import * as drilldown from 'highcharts/modules/drilldown.src.js'**
use providers in NgModule as :
providers: [
{provide: HIGHCHARTS_MODULES,
useFactory: () => [ drilldown]
}]
在您的 app.module.ts
中导入 angular-charts 和 drilldown 如下!
import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import * as drilldown from 'highcharts/modules/drilldown.src';
imports: [ChartModule]
providers: [
{ provide: HIGHCHARTS_MODULES, useFactory: () => [more, exporting, drilldown] }
]
在您的 component.ts 文件中以与您相同的方式初始化图表。
如果它抛出错误 Property 'type' is missing in type '{ name: string; data: ((string | number)[] | { name: string; y: number; drilldown: string; })[]; }' but required in type
然后添加类型:未定义到对象。它会按预期工作。