나는 aurelia, chart.js 및 moment.js에 문제가 있습니다.Aurelia - 처리되지 않은 거부 - Chart.js 및 Moment.js
사실 저는 다른 클래스에서 별도로 moment.js와 chart.js를 사용하고 있습니다. 내가 x 배율에 시간 dimesion와 플롯을 그리는 chart.js 시간 규모 기능을 사용하려고 그럼에도 불구 경우이 오류를 얻을 :
[Warning] Unhandled rejection Error: Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale. Download at https://momentjs.com (vendor-bundle.js, line 1395)
[email protected]://localhost:9001/scripts/vendor-bundle.js:35970:13268
[email protected]://localhost:9001/scripts/vendor-bundle.js:35968:6217
[email protected]://localhost:9001/scripts/vendor-bundle.js:35968:7779
[email protected]://localhost:9001/scripts/vendor-bundle.js:35967:28931
[email protected]://localhost:9001/scripts/vendor-bundle.js:35967:27712
[email protected]://localhost:9001/scripts/vendor-bundle.js:35967:27429
[email protected]://localhost:9001/scripts/vendor-bundle.js:35968:22824
[email protected]://localhost:9001/scripts/app-bundle.js:1155:22
[email protected]://localhost:9001/scripts/app-bundle.js:1160:22
[email protected]://localhost:9001/scripts/vendor-bundle.js:21894:32
[email protected]://localhost:9001/scripts/vendor-bundle.js:19969:32
[email protected]://localhost:9001/scripts/vendor-bundle.js:20323:23
[email protected]://localhost:9001/scripts/vendor-bundle.js:19974:29
[email protected]://localhost:9001/scripts/vendor-bundle.js:20323:23
From previous event:
[email protected]://localhost:9001/scripts/app-bundle.js:579:29
From previous event:
[email protected][native code]
From previous event:
[email protected]://localhost:9001/scripts/vendor-bundle.js:5432:38
[email protected]://localhost:9001/scripts/vendor-bundle.js:4620:57
[email protected]://localhost:9001/scripts/vendor-bundle.js:4912:27
[email protected]://localhost:9001/scripts/vendor-bundle.js:5293:45
[email protected]://localhost:9001/scripts/vendor-bundle.js:3798:35
[email protected]://localhost:9001/scripts/vendor-bundle.js:4849:21
[email protected]://localhost:9001/scripts/vendor-bundle.js:4525:32
은 내가 aurelia.json 파일에 libs와 추가 .. 있습니다 ..
${value}
실제로 순간 문자열로 대체됩니다 것을이 템플릿 구성 요소 생성
{
"name": "moment",
"path": "../node_modules/moment/min/moment.min"
},
{
"name": "chart.js",
"path": "../node_modules/chart.js/dist",
"main": "Chart.min",
"deps": ["moment"]
},
...
참고. 그래서 moment.js ...
<template>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${value}</h3>
</div>
<div class="panel-body">
<canvas id="mychart"/>
</div>
</div>
</template>
을 사용할 수 있습니다 여기이 타이프 라이터 클래스 쓴 : 귀하의 지원을 사전에
import {autoinject} from 'aurelia-framework';
import {SalesService} from "../../service/SalesService";
import {EventAggregator} from "aurelia-event-aggregator";
import {Subscription} from "aurelia-event-aggregator";
import {FilterService} from "../../service/FilterService";
import {SalesPeriodSum} from "../../domain/SalesPeriodSum";
import * as moment from 'moment';
import Moment = moment.Moment;
import * as Chart from 'chart.js';
@autoinject
export class SalesInPeriod {
public value: Moment;
private _salesService: SalesService;
private _eventAggregator: EventAggregator;
private _subscription: Subscription;
private _filterService: FilterService;
private _items: Array<SalesPeriodSum>;
constructor(salesService: SalesService, eventAggregator: EventAggregator, filterService: FilterService) {
this._salesService = salesService;
this._eventAggregator = eventAggregator;
this._filterService = filterService;
}
private load() {
this._salesService.getSalesInPeriod(this._filterService.request).then(result => {
this._items = result;
});
this.value = moment();
let config = {
type: 'line',
data: {
datasets: [{
label: "Dataset with string point data",
data: [{
x: moment().add(0, 'days'),
y: 100
}, {
x: moment().add(1, 'days'),
y: 120
}, {
x: moment().add(2, 'days'),
y: 90
}, {
x: moment().add(3, 'days'),
y: 105
}],
fill: false
}]
},
options: {
responsive: true,
title: {
display: true,
text: "Chart.js Time Point Data"
},
scales: {
xAxes: [{
type: "time",
display: true,
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'value'
}
}]
}
}
};
let ctx = document.getElementById("mychart");
new Chart(ctx, config);
}
attached() {
this._subscription = this._eventAggregator.subscribe('filter_changed', response => this.load());
this.load();
}
detached() {
this._subscription.dispose();
}
get items(): Array <SalesPeriodSum> {
return this._items;
}
}
감사합니다.
감사합니다. chart.bundle.min.js 파일을로드하여 솔루션을 찾았습니다. 이 스크립트에는 moment.js가 포함되어 있습니다. 그러나 실제로 그것은 둘 다 원하는 것이 아닙니다. 그래서 창에 직접 변수를 추가하는 유일한 방법은 다음 문장을 사용하는 것입니다 :'import * '순간부터'moment '; ( 창) .Moment = moment;'. 그럼 나는 콘솔에서 순간을 볼 수 있지만 위에서 같은 오류가 발생합니다. –
Fritz
@Fritz, ** 순간 **을 찾고 ** 순간 **을 찾고 있기 때문일 수 있습니다. https://github.com/chartjs/Chart.js/blob/master/src/scales/scale .time.js # L5 https://github.com/chartjs/Chart.js/blob/master/src/scales/scale.time.js#L375 – Patrick