ठीक है - @Pogrindis की मदद से मुझे लगता है कि मुझे एक उपयोगी, बहुत जटिल समाधान नहीं मिला है।
बस here से chart.js के लिए टाइपिंग परिभाषा जोड़ने और एक कस्टम निर्देश में यह संदर्भित करके मैं अंत में यह है:
chart.directive.ts
/// <reference path="../../typings/chartjs/chart.d.ts" />
import {Directive, ElementRef, Renderer, Input} from 'angular2/core';
@Directive({
selector: '[chart]'
})
export class ChartDirective {
constructor(el: ElementRef, renderer: Renderer) {
//el.nativeElement.style.backgroundColor = 'yellow';
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
}
]
};
var ctx: any = el.nativeElement.getContext("2d");
var lineChart = new Chart(ctx);
////var lineChartOptions = areaChartOptions;
////lineChartOptions.datasetFill = false;
lineChart.Line(data);
}
}
app.component.ts
import {Component} from 'angular2/core';
import {ChartDirective} from './chart.directive';
@Component({
directives: [ChartDirective],
selector: 'chart-graph',
templateUrl: '/js/app/template.html'
})
export class AppComponent { }
और template.html:
<canvas id="myChart" chart width="400" height="400"></canvas>
आप क्या करने की कोशिश कर रहे हैं? और टाइपस्क्रिप्ट के साथ क्या करना है? आपका प्रश्न और कोड टाइपस्क्रिप्ट के बारे में कुछ भी नहीं दिखाता है .. – Pogrindis
बस मैं टाइपरक्रिप्ट में अपना कोणीय 2 कोडिंग कर रहा हूं। मैंने सोचा कि यह प्रासंगिक था, क्योंकि मैं अपनी टाइपस्क्रिप्ट फ़ाइल (जैसे हैक/वर्कअराउंड के प्रकार) में chart.js जावास्क्रिप्ट नहीं लिख सकता – Dynde
यदि आप टाइपस्क्रिप्ट लिख रहे हैं तो आपको ब्राउज़र के जावास्क्रिप्ट को संकलित करना होगा क्योंकि ब्राउज़र केवल जावास्क्रिप्ट को टाइपस्क्रिप्ट नहीं समझते हैं। – Jai