I have such a code and don't know why in anonymous function passed to nv.addGraph() I can't access variables from outer function like a, zcls or this.model.
function (out) {
// Here you call the "this" means the widget instance. (@see Mylable.js)
var zcls = this.getZclass(),
uuid = this.uuid;
// The this.domAttrs_() means it will prepare some dom attributes,
// like the pseudo code below
/*
* class="${zcls} ${this.getSclass()}" id="${uuid}"
*/
var a = this.domAttrs_();
out.push('<span ', this.domAttrs_(), '>fds</span><div id="chart"><svg></svg></div>');
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
.transitionDuration(350)
.reduceXTicks(true) // If 'false', every single x-axis tick label
// will be rendered.
.rotateLabels(0) // Angle to rotate x-axis labels.
.showControls(true) // Allow user to switch between 'Grouped' and
// 'Stacked' mode.
.groupSpacing(0.1) // Distance between each group of bars.
;
chart.xAxis.tickFormat(d3.format(',f'));
chart.yAxis.tickFormat(d3.format(',.1f'));
var data = [{
key: 'Some key',
color: '#ff44ee',
values: [{
x: 1,
y: 3
}, {
x: 3,
y: 4
}]
}]
d3.select('#chart svg').datum(data).call(chart);
// d3.select('#chart svg').datum(this.model.data).call(chart);
var someData = this.model.data;
nv.utils.windowResize(chart.update);
return chart;
});
This function is in some way used in ZKoss Widget so in this function it's possible to access its properties like this.model, but it's not possible in inner anonymous function. I have no idea what's wrong with it, I just started coding in JS.