BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
Angular 2: <input type="button" onclick="UpdateChart()" value="Update using Redraw method" /> var data5 = [ { x: 0, y: 5 }, { x: 1, y: 12 }, { x: 2, y: 8 }, { x: 3, y: 10 }, { x: 4, y: 15 } ]; var data10 = [ { x: 0, y: 5 }, { x: 1, y: 12 }, { x: 2, y: 8 }, { x: 3, y: 10 }, { x: 4, y: 15 }, { x: 5, y: 5 }, { x: 6, y: 12 }, { x: 7, y: 8 }, { x: 8, y: 10 }, { x: 9, y: 15 }, ]; function UpdateChart() { //Get Chart instance var chart = $('#container').ejChart('instance'); //Change the data source chart.model.series[0].dataSource = chart.model.series[0].dataSource.length == 5 ? data10 : data5; //Redraw the chart $('#container').ejChart('redraw'); } |
Angular 2: <ej-chart #contain id="container"></ej-chart> @ViewChild('contain') chart: any; ngAfterViewInit() { // After the view is initialized, chart will be available this.update(); } update() { this.chart.widget.redraw(); } |
import { Component, ViewEncapsulation, ViewChild, Injectable } from '@angular/core';import { CommonModule } from "@angular/common";import { EJComponents } from './ej/core';import { EJ_CHART_COMPONENTS } from './ej/chart.component';declare let ej: any;@Component({selector: 'ej-app',templateUrl: 'app/app.component.html'})export class AppComponent {data1 = [{ x: 0, y: 5 }, { x: 1, y: 12 }, { x: 2, y: 8 }, { x: 3, y: 10 }, { x: 4, y: 15 }];data2 = [{ x: 0, y: 7 }, { x: 1, y: 2 }, { x: 2, y: 5 }, { x: 3, y: 14 }, { x: 4, y: 10 }];@ViewChild('Chart') Chart: any;private Tabelle1;constructor() {this.Tabelle1 = this.data1;}update() {this.Chart.widget.redraw();}changeChart() {if (this.Tabelle1 == this.data1) this.Tabelle1 = this.data2;else this.Tabelle1 = this.data1;console.log(this.Tabelle1);this.Chart.widget.redraw();}}
app.component.html:
<h2>Syncfusion Javascript Angular 2 Component</h2><ej-chart #Chart id="line" style="height: 320px; width: 420px; display:block;" [isResponsive]="true" [legend.visible]="true"primaryYAxis.title.text="y" primaryXAxis.title.text="x" ><e-seriescollection><e-series name="Front" fill=#1B93D0 [dataSource]="Tabelle1" xName="x" yName="y"></e-series></e-seriescollection></ej-chart><button (click)="changeChart()">changeData</button>
When the page loads I can see the data of the array data1.
I hoped to see data2 in the chart after clicking the Button.
The console Log shows the data i hoped to see in the chart.
Do you have any hints?
Regards
Bernd
Angular 2: <button (click)="changeChart()">changeData</button> changeChart() { this.Chart.widget.model.series[0].dataSource = this.data2; this.Chart.widget.redraw(); } |