gpt4 book ai didi

angular - crossfilter2__WEBPACK_IMPORTED_MODULE_3__ 不是函数

转载 作者:行者123 更新时间:2023-12-04 12:24:55 26 4
gpt4 key购买 nike

我正在尝试将 dc.js 图表库集成到我的 angular 项目中。我遵循了 SO 上的链接,该链接指示如何将 dc.js 图表与 angular2+ dc.js charts with Angular2+ 集成.我运行以下行来安装所需的所有软件包。npm i --save dc @types/dc crossfilter2 d3 @types/d3我有一个基本的 Angular 项目。我的 Angular 版本是 7,我还附上了我的 app.component.html , app.component.ts , app.module.ts , package.json和我的 angular.json下面的文件。
app.component.html <div #nameOfDiv></div> app.component.ts

import * as d3 from "d3";
import * as dc from "dc";
import * as crossfilter from "crossfilter2";
import { Dimension } from "crossfilter2";

interface Data {
letter: string;
frequency: number;
}

@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
@ViewChild("nameOfDiv", { static: false }) chartDiv: ElementRef;

title = "DC";

private chart: dc.PieChart;
private ndx: any = crossfilter<Data>([
{ letter: "B", frequency: 2 },
{ letter: "A", frequency: 10 }
]);

paintChart(): void {
this.chart = dc.pieChart("#pie");
let dim = this.ndx.dimension((d: any) => d.letter);
let group = dim.group().reduceCount();
this.chart
.width(200)
.height(200)
.dimension(dim)
.group(group);
dc.renderAll();
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"DC": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/DC",
"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"
],
"scripts": []
},
"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": "DC:build"
},
"configurations": {
"production": {
"browserTarget": "DC:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "DC: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"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "DC:serve"
},
"configurations": {
"production": {
"devServerTarget": "DC:serve:production"
}
}
}
}
}},
"defaultProject": "DC"
}
package.json
{
"name": "Test",
"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.14",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@types/d3": "^5.7.2",
"@types/dc": "0.0.29",
"crossfilter2": "^1.5.2",
"d3": "^5.15.0",
"dc": "^4.0.0",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.21",
"@angular/cli": "~8.3.21",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@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"
}
}

当我编译并运行这个项目时,我看到以下错误。
Error : crossfilter2__WEBPACK_IMPORTED_MODULE_3__ is not a function
我该如何解决这个问题?

最佳答案

我也遇到了同样的问题,以下方法对我有用。

import * as crossfilter from 'crossfilter2/crossfilter';
crossFilterObj = crossfilter(data);

关于angular - crossfilter2__WEBPACK_IMPORTED_MODULE_3__ 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59925481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com