When using addSeries + templates I’d like to find out, what is the series I’m working on:
myChart.addSeries({
value:"#sales1#",
color:"#45abf5",
label:function(row) {
/* what is the current series ? */
}
});
Is this possible?
When using addSeries + templates I’d like to find out, what is the series I’m working on:
myChart.addSeries({
value:"#sales1#",
color:"#45abf5",
label:function(row) {
/* what is the current series ? */
}
});
Is this possible?
Hello
If you want to set common label - there is no way to implement this.
There is one item object in the Label tamplate ONLY
I want to do some custom formatting inside the template function, that’s all. And I don’t know which row property corresponds to the series I’m working with…
Try the next:
myChart.addSeries({
value:"#sales1#",
color:"#45abf5",
label:function(row) {
someYourFunction("sales1",row);
}
});
Actually, hardcoding is what I want to avoid:
for(k in series){
myChart.addSeries({
value:"#"+series[k].value+"#",
color:series[k].color,
label:function(row) {
someYourFunction("sales1",row); // it doesn't work
}
});
}
When we posted someYourFunction(“sales1”,row), we meant that you can pass the series value into custom function. “sales1” was the series value ("#sales1#")
Doesn’t work either, the call to someYourFunction is out of scope:
for(k in series){
myChart.addSeries({
value:"#"+series[k].value+"#",
color:series[k].color,
label:function(row) {
someYourFunction(series[k].value,row);
}
});
}
You may try to use closure approach. For example:
for(k in series){
myChart.addSeries({
value:"#"+series[k].value+"#",
color:series[k].color,
label: (function(row){
var seriesName = k;
return function(row){
/*your code*/
}
})()
});
}
Thanks Darya! That’s exactly what I was looking for. Great solution!
You are welcome!