From 5c1df459e7a63df83744c992a3df536f1722d218 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Wed, 9 Nov 2016 20:09:34 -0200 Subject: [PATCH] =?UTF-8?q?fix(charts):=20line=20charts=20wouldn=E2=80=99t?= =?UTF-8?q?=20render=20with=20empty=20data=20set=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The line chart wouldn’t render at all if an empty array is used on the [data] attribute, the following error would be thrown: TypeError: Cannot read property 'xValue' of undefined I narrowed it down to the translation of the data, where it was assumed that the value would be defined at all times, which isn’t the case if data is an empty array. This fix solves the problem. --- src/platform/charts/chart-line/chart-line.component.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform/charts/chart-line/chart-line.component.ts b/src/platform/charts/chart-line/chart-line.component.ts index 11a2c5d9c3..2c31d22ea4 100644 --- a/src/platform/charts/chart-line/chart-line.component.ts +++ b/src/platform/charts/chart-line/chart-line.component.ts @@ -112,7 +112,13 @@ export class TdChartLineComponent extends ChartComponent { line.append('text') .datum((d: any) => { return {id: d.id, value: d.values[d.values.length - 1]}; }) - .attr('transform', (d: any) => { return 'translate(' + x(d.value.xValue) + ',' + y(d.value.yValue) + ')'; }) + .attr('transform', (d: any) => { + if (!d.value) { + return undefined; + } else { + return 'translate(' + x(d.value.xValue) + ',' + y(d.value.yValue) + ')'; + } + }) .attr('x', 3) .attr('dy', '0.35em') .style('font', '10px sans-serif')