import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
// import the ChartModule for the Chart component
import { ChartModule, LineSeriesService, MarkerService} from '@syncfusion/ej2-ng-charts';
import { AppComponent } from './app.component';
@NgModule({
//declaration of ej2-ng-charts module into NgModule
imports: [ BrowserModule, ChartModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: [LineSeriesService, MarkerService,]
})
export class AppModule { }
|
`<ej-chart id='chartcontainer' >
</ej-chart>` |
export class AppComponent {
public data: Object[] = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 30 }
];
}
|
`<ej-chart id='chartcontainer' [title]='title' [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis'>
<e-series-collection>
<e-series [dataSource]='data' type='Line' xName='x' yName='y' name='Japan' width=2 [marker]='marker'> </e-series>
</e-series-collection>
</ej-chart>` |
export class AppComponent {
public marker: Object = { visible: true, height: 10, width: 10 };
} |
After some trial and error, I managed to get the chart out. Thank you.
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { Chart } from '@syncfusion/ej2-ng-charts';
@Component({
selector: 'app-container',
// specifies the template string for the Charts component
template:
`<button type="button" (click)="ChangeData()">Swap DataSource</button>
<ej-chart #chart id='chartcontainer'></ej-chart>`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
@ViewChild('chart')
public chart: Chart;
public data1: Object[] = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 30 }
];
public data2: Object[] = [
{ x: 2005, y: 30 }, { x: 2006, y: 55 }, { x: 2007, y: 40 }, { x: 2008, y: 70 },
{ x: 2009, y: 60 }, { x: 2010, y: 35 }, { x: 2011, y: 20 }
];
public ChangeData() {
this.chart.series[0].dataSource = (this.chart.series[0].dataSource === this.data1) ? this.data2 : this.data1;
this.chart.refresh();
}
} |
It worked! Thank you very much for the assistance.
One question, am I required to create a new thread if it's a non-chart related issue?
Is it possible to use a service to call out its data to a chart? If yes, I am facing difficulties in pulling out data using service for Angular. I hope you can help me solve this issue by giving me an example. I have attach a file consist of the failed codes.
public data1exp: Object[] = [
this.data1
];
|
Thank you. It works!