首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >钻下(高度图)不工作在角5

钻下(高度图)不工作在角5
EN

Stack Overflow用户
提问于 2018-04-06 10:02:41
回答 3查看 5K关注 0票数 8

尝试了导入模块的新方法。(app.module.ts)。在app.module中导入更多的模块。在组件中也有json结构和钻取。仍然无法在页面上呈现

代码语言:javascript
复制
   " 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
          }
      },

//能够在呈现时使用系列并能很好地工作,但单击后,钻//下不能工作

代码语言:javascript
复制
    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。

代码语言:javascript
复制
    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 { }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-04-10 03:14:38

代码语言:javascript
复制
**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]
}]
票数 3
EN

Stack Overflow用户

发布于 2018-04-06 10:58:02

使用官方npm高级图表

stackblitz演示

下面的app.component.ts

代码语言:javascript
复制
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]
          ]
        }]
      }
    })
  }

}
票数 10
EN

Stack Overflow用户

发布于 2019-10-03 22:14:38

在您的app.module.ts导入角图和钻取如下所示!

代码语言:javascript
复制
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,那么向对象添加type: undefined。它将如预期的那样工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49690245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档