Skip to content

Commit

Permalink
fix(charts): line charts wouldn’t render with empty data set (#138)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fcoury authored and emoralesb05 committed Nov 9, 2016
1 parent 9b87990 commit 5c1df45
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/platform/charts/chart-line/chart-line.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 5c1df45

Please sign in to comment.