I have a composite chart in dc.js and trying to add a line calculated against existing groups:
Basically I'm trying to get the diff of Actuals vs Forecast (rDiffPct
) as a percentage as follows: (Actuals - Forecast) / Forecast
but getting either Nan
or in,fin,ity
.
var dateDim = ndx.dimension(function (d) { return d.date; });
var rHistByDate = dateDim.group().reduceSum(function (d) { return d.Hist ; }) // Forecast
var rFcstByDate = dateDim.group().reduceSum(function (d) { return d.Fcst ; }) // Actuals
var rDiff = dateDim.group().reduceSum(function (d) { return d.Hist - d.Fcst; }) // Difference From Forecast
var rDiffPct = dateDim.group().reduceSum(function (d) { return Math.round((d.Hist - d.Fcst) / d.Fcst); });
Both rHistByDate
and rFcstByDate
render ok.
The Chart renders fine with other results but not with rDiffPct
.
Chart uses the following:
.dimension(dateDim)
.group(rHistByDate)
dc.lineChart(rViz_Main2b).group(rDiffPct,"Variation - hist-fcst").useRightYAxis(false).colors('#2d00b3').dashStyle([5,5]).renderDataPoints({radius: 3,fillOpacity: 0.8,strokeOpacity: 0.8})
I'm obviously missing something or going about it the wrong way.