Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度8与海图7的积分_Angular_Highcharts_Angular Highcharts - Fatal编程技术网

Angular 角度8与海图7的积分

Angular 角度8与海图7的积分,angular,highcharts,angular-highcharts,Angular,Highcharts,Angular Highcharts,我试图从我的angular应用程序(使用angular 8)中显示highstock UI(使用Hightchart 7),但它没有出现。下面是代码。也许,我缺少了一个步骤,缺少了配置,缺少了一些东西。我已经审查了这里的其他条目,但建议并没有解决这个问题 下面是angular.json文件 { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot":

我试图从我的angular应用程序(使用angular 8)中显示highstock UI(使用Hightchart 7),但它没有出现。下面是代码。也许,我缺少了一个步骤,缺少了配置,缺少了一些东西。我已经审查了这里的其他条目,但建议并没有解决这个问题

下面是angular.json文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "highchart": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/highchart",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/highcharts/css/stocktools/gui.css",
              "node_modules/highcharts/css/annotations/popup.css"
            ],
            "scripts": [
              "node_modules/highcharts/indicators/indicators-all.js",
              "node_modules/highcharts/modules/drag-panes.js",
              "node_modules/highcharts/modules/annotations-advanced.js",
              "node_modules/highcharts/modules/price-indicator.js",
              "node_modules/highcharts/modules/full-screen.js",
              "node_modules/highcharts/modules/stock-tools.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "highchart:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "highchart:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "highchart:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/highcharts/css/stocktools/gui.css",
              "node_modules/highcharts/css/annotations/popup.css"
            ],
            "scripts": [
              "node_modules/highcharts/indicators/indicators-all.js",
              "node_modules/highcharts/modules/drag-panes.js",
              "node_modules/highcharts/modules/annotations-advanced.js",
              "node_modules/highcharts/modules/price-indicator.js",
              "node_modules/highcharts/modules/full-screen.js",
              "node_modules/highcharts/modules/stock-tools.js"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "highchart:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "highchart:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "highchart"
}
{
  "name": "highchart",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.11",
    "@angular/common": "~8.2.11",
    "@angular/compiler": "~8.2.11",
    "@angular/core": "~8.2.11",
    "@angular/forms": "~8.2.11",
    "@angular/platform-browser": "~8.2.11",
    "@angular/platform-browser-dynamic": "~8.2.11",
    "@angular/router": "~8.2.11",
    "highcharts": "^7.2.0",
    "highcharts-angular": "^2.4.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.12",
    "@angular/cli": "~8.3.12",
    "@angular/compiler-cli": "~8.2.11",
    "@angular/language-service": "~8.2.11",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}
下面是package.json文件

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "highchart": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/highchart",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/highcharts/css/stocktools/gui.css",
              "node_modules/highcharts/css/annotations/popup.css"
            ],
            "scripts": [
              "node_modules/highcharts/indicators/indicators-all.js",
              "node_modules/highcharts/modules/drag-panes.js",
              "node_modules/highcharts/modules/annotations-advanced.js",
              "node_modules/highcharts/modules/price-indicator.js",
              "node_modules/highcharts/modules/full-screen.js",
              "node_modules/highcharts/modules/stock-tools.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "highchart:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "highchart:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "highchart:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/highcharts/css/stocktools/gui.css",
              "node_modules/highcharts/css/annotations/popup.css"
            ],
            "scripts": [
              "node_modules/highcharts/indicators/indicators-all.js",
              "node_modules/highcharts/modules/drag-panes.js",
              "node_modules/highcharts/modules/annotations-advanced.js",
              "node_modules/highcharts/modules/price-indicator.js",
              "node_modules/highcharts/modules/full-screen.js",
              "node_modules/highcharts/modules/stock-tools.js"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "highchart:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "highchart:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "highchart"
}
{
  "name": "highchart",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.11",
    "@angular/common": "~8.2.11",
    "@angular/compiler": "~8.2.11",
    "@angular/core": "~8.2.11",
    "@angular/forms": "~8.2.11",
    "@angular/platform-browser": "~8.2.11",
    "@angular/platform-browser-dynamic": "~8.2.11",
    "@angular/router": "~8.2.11",
    "highcharts": "^7.2.0",
    "highcharts-angular": "^2.4.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.12",
    "@angular/cli": "~8.3.12",
    "@angular/compiler-cli": "~8.2.11",
    "@angular/language-service": "~8.2.11",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  }
}
在app.module.ts文件下面

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { HighchartsChartModule } from 'highcharts-angular';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HighchartsChartModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
下面是app.component.html文件

<div>
  <highcharts-chart 
  [Highcharts]="Highcharts"
  [options]="chartOptions"
  [constructorType]="stockChart"
  style="width: 100%; height: 400px; display: block;"
></highcharts-chart>
</div>

我找不到stock tools模块的初始化,因此可能会出现问题

在图表组件中:

import * as Highcharts from "highcharts/highstock";
import * as HIndicatorsAll from "highcharts/indicators/indicators-all";
import * as HDragPanes from "highcharts/modules/drag-panes";
import * as HAnnotationsAdvanced from "highcharts/modules/annotations-advanced";
import * as HPriceIndicator from "highcharts/modules/price-indicator";
import * as HFullScreen from "highcharts/modules/full-screen";
import * as HStockTools from "highcharts/modules/stock-tools";

HIndicatorsAll(Highcharts);
HDragPanes(Highcharts);
HAnnotationsAdvanced(Highcharts);
HPriceIndicator(Highcharts);
HFullScreen(Highcharts);
HStockTools(Highcharts);
另外,将样式添加到应用程序的主样式文件
styles.css

演示:


显然,Highcharts第7版发生了一些变化。当您试图使用导入指令导入这些库时,会出现以下错误消息

消息错误:

This expression is not callable.
  Type 'typeof import("/Users/tritan/Documents/highchart/node_modules/highcharts/modules/drag-panes")' has no call signatures.
我找到了一个解决方案,请检查以下代码版本:

declare var require: any;
import { Component } from '@angular/core';
import * as Highcharts from "highcharts/highstock";
import * as HIndicatorsAll from "highcharts/indicators/indicators-all";
const HDragPanes = require("highcharts/modules/drag-panes");
import * as HAnnotationsAdvanced from "highcharts/modules/annotations-advanced";
const HPriceIndicator = require("highcharts/modules/price-indicator");
const HFullScreen = require("highcharts/modules/full-screen");
const HStockTools = require("highcharts/modules/stock-tools");

HIndicatorsAll(Highcharts);
HDragPanes(Highcharts);
HAnnotationsAdvanced(Highcharts);
HPriceIndicator(Highcharts);
HFullScreen(Highcharts);
HStockTools(Highcharts);

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'highchart';
  Highcharts: typeof Highcharts = Highcharts;

  ohlc: any = [
                [1508765400000, 156.89, 157.69, 155.5, 156.17],
                [1508851800000, 156.29, 157.42, 156.2, 157.1],
                [1508938200000, 156.91, 157.55, 155.27, 156.41],
                [1509024600000, 156.29, 157.42, 156.2, 157.1], 
                [1509111000000, 156.25, 157.45, 156.25, 157.15]
              ];
  volume: any = [
                  [1508765400000, 21207100],
                  [1508851800000, 17757200], 
                  [1508938200000, 21984300], 
                  [1509024600000, 17757200], 
                  [1509111000000, 21207100]
                ];

  chartOptions = {
    yAxis: [{
        labels: {
            align: 'left'
        },
        height: '80%',
        resize: {
   ..........

奇怪的是,为什么在定义变量类型时使用“typeof”?它属于HighCharts类型,所以为什么不直接说:
HighCharts:HighCharts=HighCharts
@FallenReapper他使用了组件中的代码,我已经编写了这些文档,这就是为什么我要回答:在编写文档时,这是获得工作代码所必需的,现在看起来不像是破坏了任何东西。