diff --git a/src/app/pages/charts/components/chartistJs/chartistJs.component.ts b/src/app/pages/charts/components/chartistJs/chartistJs.component.ts index 3d7efa97..923d8797 100644 --- a/src/app/pages/charts/components/chartistJs/chartistJs.component.ts +++ b/src/app/pages/charts/components/chartistJs/chartistJs.component.ts @@ -2,6 +2,7 @@ import {Component, ViewEncapsulation} from '@angular/core'; import {BaCard} from '../../../../theme/components'; import {ChartistJsService} from "./chartistJs.service"; +import {BaChartistChart} from '../../../../theme/components'; @Component({ selector: 'chartist-js', @@ -9,9 +10,11 @@ import {ChartistJsService} from "./chartistJs.service"; providers: [ChartistJsService], encapsulation: ViewEncapsulation.None, styles: [require('chartist/dist/chartist.css'), require('./chartistJs.scss')], - directives: [BaCard], + directives: [BaCard, BaChartistChart], template: require('./chartistJs.html'), }) + +// TODO: service for the data export class ChartistJs { private simpleLineOptions = { @@ -196,19 +199,6 @@ export class ChartistJs { constructor(private _chartistJsService:ChartistJsService) { } - ngOnInit() { - new Chartist.Line('#line-chart', this.simpleLineData, this.simpleLineOptions); - new Chartist.Line('#area-chart', this.areaLineData, this.areaLineOptions); - new Chartist.Line('#bi-chart', this.biLineData, this.biLineOptions); - - new Chartist.Bar('#simple-bar', this.simpleBarData, this.simpleBarOptions); - new Chartist.Bar('#multi-bar', this.multiBarData, this.multiBarOptions, this.multiBarResponsive); - new Chartist.Bar('#stacked-bar', this.stackedBarData, this.stackedBarOptions); - - new Chartist.Pie('#simple-pie', this.simplePieData, this.simplePieOptions, this.getResponsive(20, 80)); - new Chartist.Pie('#label-pie', this.labelsPieData, this.labelsPieOptions); - new Chartist.Pie('#donut', this.simpleDonutData, this.simpleDonutOptions, this.getResponsive(5, 40)); - } getResponsive(padding, offset) { return [ diff --git a/src/app/pages/charts/components/chartistJs/chartistJs.html b/src/app/pages/charts/components/chartistJs/chartistJs.html index 761032e2..dc3e8378 100644 --- a/src/app/pages/charts/components/chartistJs/chartistJs.html +++ b/src/app/pages/charts/components/chartistJs/chartistJs.html @@ -3,22 +3,51 @@
Simple line chart
-
+ + +
Line chart with area
-
+ + +
Bi-polar line chart with area only
-
+ +
Simple bar chart
-
+ + +
Multi-line labels bar chart
-
+ + +
Stacked bar chart
-
+ +
@@ -28,13 +57,27 @@
Simple Pie
-
+ +
Pie with labels
-
+ +
Donut
-
+ +
diff --git a/src/app/theme/components/baChartistChart/baChartistChart.component.ts b/src/app/theme/components/baChartistChart/baChartistChart.component.ts new file mode 100644 index 00000000..eb455616 --- /dev/null +++ b/src/app/theme/components/baChartistChart/baChartistChart.component.ts @@ -0,0 +1,34 @@ +import {Component, ViewEncapsulation, Input, Output, ElementRef, EventEmitter} from '@angular/core'; + +import './baChartistChart.loader.ts'; + +@Component({ + selector: 'ba-chartist-chart', + styles: [require('chartist/dist/chartist.css'), require('./baChartistChart.scss')], + template: require('./baChartistChart.html'), + encapsulation: ViewEncapsulation.None, + providers: [], +}) +export class BaChartistChart { + + @Input() baChartistChartType:string; + @Input() baChartistChartData:Object; + @Input() baChartistChartOptions:Object; + @Input() baChartistChartResponsive:Object; + @Input() baChartistChartClass:string; + @Output() onChartReady = new EventEmitter(); + + constructor (private _elementRef:ElementRef) { + } + + ngOnInit() { + } + + ngAfterViewInit() { + let el = this._elementRef.nativeElement.querySelector('.ba-chartist-chart'); + + let chart = new Chartist[this.baChartistChartType](el, this.baChartistChartData, this.baChartistChartOptions, this.baChartistChartResponsive); + this.onChartReady.emit(chart); + } + +} diff --git a/src/app/theme/components/baChartistChart/baChartistChart.html b/src/app/theme/components/baChartistChart/baChartistChart.html new file mode 100644 index 00000000..961c75b5 --- /dev/null +++ b/src/app/theme/components/baChartistChart/baChartistChart.html @@ -0,0 +1 @@ +
diff --git a/src/app/theme/components/baChartistChart/baChartistChart.loader.ts b/src/app/theme/components/baChartistChart/baChartistChart.loader.ts new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/app/theme/components/baChartistChart/baChartistChart.loader.ts @@ -0,0 +1 @@ + diff --git a/src/app/theme/components/baChartistChart/baChartistChart.scss b/src/app/theme/components/baChartistChart/baChartistChart.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/theme/components/baChartistChart/index.ts b/src/app/theme/components/baChartistChart/index.ts new file mode 100644 index 00000000..a2a45e82 --- /dev/null +++ b/src/app/theme/components/baChartistChart/index.ts @@ -0,0 +1 @@ +export * from './baChartistChart.component.ts'; diff --git a/src/app/theme/components/index.ts b/src/app/theme/components/index.ts index 0a862979..06e6cae8 100644 --- a/src/app/theme/components/index.ts +++ b/src/app/theme/components/index.ts @@ -4,3 +4,4 @@ export * from './sidebar'; export * from './contentTop'; export * from './baCard'; export * from './baAmChart'; +export * from './baChartistChart';