gpt4 book ai didi

javascript - ng2-charts\ng2-charts.js 不导出 ChartsModule

转载 作者:太空狗 更新时间:2023-10-29 17:37:09 27 4
gpt4 key购买 nike

我正在尝试使用 NG2-Charts ( http://valor-software.com/ng2-charts/ ) 的基本示例

我复制粘贴了 HTML 部分

<div style="display: block">
<canvas baseChart
[datasets]="barChartData"
[labels]="barChartLabels"
[options]="barChartOptions"
[legend]="barChartLegend"
[chartType]="barChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>

和 TypeScript 部分

public barChartOptions:any = {
scaleShowVerticalLines: false,
responsive: true
};
public barChartLabels:string[] =
['2006', '2007', '2008', '2009', '2010','2011', '2012'];

public barChartType:string = 'bar';
public barChartLegend:boolean = true;

public barChartData:any[] = [
{data: [65, 59, 80, 81, 56, 55, 40], label: 'Series A'},
{data: [28, 48, 40, 19, 86, 27, 90], label: 'Series B'}
];

// events
public chartClicked(e:any):void {
console.log(e);
}

public chartHovered(e:any):void {
console.log(e);
}

public randomize():void {
// Only Change 3 values
let data = [
Math.round(Math.random() * 100),
59,
80,
(Math.random() * 100),
56,
(Math.random() * 100),
40];
let clone = JSON.parse(JSON.stringify(this.barChartData));
clone[0].data = data;
this.barChartData = clone;
/**
* (My guess), for Angular to recognize the change in the dataset
* it has to change the dataset variable directly,
* so one way around it, is to clone the data, change it and then
* assign it;
*/
}

我运行 npm install ng2-charts --save, npm install chart.js --save

我还在 app.module.ts 中导入了 ChartsModule

import { ChartsModule } from 'ng2-charts/ng2-charts';
@NgModule({
imports: [ChartsModule]
})

After importing ChartsModule I am getting an error that ng2-charts\ng2-charts.js does not export ChartsModule. Click to view the image of an error

有没有人知道如何解决这个问题?谢谢

最佳答案

评论中的第二期

It is also showing an error that "Can't bind to 'datasets' since itisn't a known property of 'canvas'

可能是因为没有将 ChartsModule 导入到呈现图表的模块中。

我遇到了同样的初始问题,并且能够通过将以下内容添加到我的 rollup-config 文件中来解决这个问题

plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: ['node_modules/rxjs/**','node_modules/ng2-charts/**'],
namedExports: {'node_modules/ng2-charts/ng2-charts.js': ['ChartsModule']}
}),
uglify()
]

这个库的文档本来可以做得更好。

希望这篇文章能对遇到类似问题的人有所帮助

关于javascript - ng2-charts\ng2-charts.js 不导出 ChartsModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40032174/

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