I am trying to implement a histogram high chart using angular 4. I am getting error "Highcharts error #17 when adding series to the chart. My code is as follows. The series happens to look fine not sure what the problem could be
Histogram component
import { Component, Input } from '@angular/core'; @Component({ selector: 'histogram', template: '<chart [options]="options" (load)="getInstance($event.context)"></chart>', styles: [` chart{ display: block; width: 100% !important; padding:0; } `] }) export class HistogramChartComponent { public options: any; chart: any; @Input() public series: any; constructor() { this.options = { chart: { type: 'histogram' }, title: { text: '' }, legend: { enabled: false }, series: [] }; } getInstance(chartInstance): void { this.chart = chartInstance; this.redraw(); } ngOnChanges(data: any) { if (!data.series.currentValue || !this.chart) return; data.series.currentValue.map(s => { this.chart.addSeries(s); }); this.chart.reflow(); } redraw() { if (!this.chart) return; console.log(this.series); this.chart.addSeries(this.series); } }
Ending surplus Component that host the histogram component
import { Component, OnInit, Input } from '@angular/core'; import { EndingSurplus } from '../../../../api/dtos'; export interface ChartSeries { data: number[]; } @Component({ selector: 'app-ending-surplus-analysis', templateUrl: './ending-surplus-analysis.component.html', }) export class EndingSurplusAnalysisComponent implements OnInit { isExpanded = false; @Input() results: Array<EndingSurplus> = []; chartSeries: Array<ChartSeries> = []; constructor() { } ngOnInit() { this.addSeries(); } private addSeries() { this.results.forEach(element => { if (element.data != null) this.chartSeries.push({ data: element.data}); }); } }
Ending surplus Component html
<div *ngIf="!showTable" class="tab-pane base-strategy-chart fade show active" id="base-strategy-chart--nva" role="tabpanel" aria-labelledby="chart-tab"> <div class="tb-container"> <div class="tb-row d-flex flex-row"> <div class="tb-cell col-12"> <histogram [series]="chartSeries"> </histogram> </div> </div> </div> <!-- sta Chart End --> </div>