diff --git a/src/sql/parts/dashboard/widgets/insights/views/charts/chartInsight.component.ts b/src/sql/parts/dashboard/widgets/insights/views/charts/chartInsight.component.ts index 3769a5e6ba..52be125f2b 100644 --- a/src/sql/parts/dashboard/widgets/insights/views/charts/chartInsight.component.ts +++ b/src/sql/parts/dashboard/widgets/insights/views/charts/chartInsight.component.ts @@ -111,7 +111,6 @@ export abstract class ChartInsight extends Disposable implements IInsightsView { protected abstract get chartType(): ChartType; - constructor( @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef, @@ -127,7 +126,6 @@ export abstract class ChartInsight extends Disposable implements IInsightsView { // This is because chart.js doesn't auto-update anything other than dataset when re-rendering so defaults are used // hence it's easier to not render until ready this.options = mixin(this.options, { maintainAspectRatio: false }); - this._isDataAvailable = true; this._changeRef.detectChanges(); TelemetryUtils.addTelemetry(this._bootstrapService.telemetryService, TelemetryKeys.ChartCreated, { type: this.chartType }); } @@ -178,6 +176,9 @@ export abstract class ChartInsight extends Disposable implements IInsightsView { unmemoize(this, 'chartData'); unmemoize(this, 'labels'); this._data = data; + if (isValidData(data)) { + this._isDataAvailable = true; + } this._changeRef.detectChanges(); } @@ -226,14 +227,14 @@ export abstract class ChartInsight extends Disposable implements IInsightsView { data: this._data.rows.map(row => Number(row[i])), label: this._data.columns[i] }; - }).slice(1); + }); } else { return this._data.rows[0].map((row, i) => { return { data: this._data.rows.map(row => Number(row[i])), label: 'Series' + i }; - }).slice(1); + }); } } } @@ -284,3 +285,19 @@ export abstract class ChartInsight extends Disposable implements IInsightsView { this.options = mixin(this.options, options); } } + +function isValidData(data: IInsightData): boolean { + if (types.isUndefinedOrNull(data)) { + return false; + } + + if (types.isUndefinedOrNull(data.columns)) { + return false; + } + + if (types.isUndefinedOrNull(data.rows)) { + return false; + } + + return true; +} diff --git a/src/sql/parts/grid/views/query/chartViewer.component.ts b/src/sql/parts/grid/views/query/chartViewer.component.ts index 3842e74441..c70d2ce1a7 100644 --- a/src/sql/parts/grid/views/query/chartViewer.component.ts +++ b/src/sql/parts/grid/views/query/chartViewer.component.ts @@ -351,7 +351,9 @@ export class ChartViewerComponent implements OnInit, OnDestroy, IChartViewAction this.componentHost.viewContainerRef.clear(); let componentRef = this.componentHost.viewContainerRef.createComponent(componentFactory); this._chartComponent = componentRef.instance; - this._chartComponent.setConfig(this._chartConfig); + if (this._chartComponent.setConfig) { + this._chartComponent.setConfig(this._chartConfig); + } this._chartComponent.data = this._executeResult; this._chartComponent.options = mixin(this._chartComponent.options, { animation: { duration: 0 } }); if (this._chartComponent.init) {