jamnikej
07-05-2024Cloud Apps
Bar Chart Label from Secondary Series Script Update
Hi all,
We have been using the script from Bar Chart - Value Label From Secondary Series (Hidden) for a while and I have noticed that it is no longer working on the latest version of windows. The original script is:
widget.on('render', function(widget,event){
// Define how each value series is used
var displaySeriesIndex = 0,
labelSeriesIndex = 1;
// Define where to put the center line
var centerLineValue = 0;
// Get a reference to the highcharts object
var chart = widget.queryResult;
// Define a centerline to add to the chart
var plotline = {
color: 'black',
dashStyle: 'solid',
width: 2,
value: centerLineValue
}
// Add the center line to the series
chart.yAxis[0].plotLines = [plotline];
// Get a reference to the series
var displaySeries = chart.series[displaySeriesIndex],
labelSeries = chart.series[labelSeriesIndex];
// Loop through each data point in then display series
displaySeries.data.forEach(function(data, index){
// Save a reference to the label value
data.labelValue = labelSeries.data[index].y;
})
// Remove the label series
chart.series.splice(labelSeriesIndex,1);
// Get a reference to the sisense formatter
var numberFormatter = prism.$injector.get('$filter')('numeric');
// Get a reference to the formatting mask of the label's series
var mask = $$get(widget.metadata.panel('values').items[labelSeriesIndex], 'format.mask', {});
// Override the label formatter function
chart.plotOptions.series.dataLabels.formatter = function(){
// Use the formatting of the label series, in order to create the value label
var newLabel = numberFormatter(this.point.options.labelValue, mask);
return newLabel;
}
})I believe the part that the issue may be that this.point.options.labelValue no longer points to something, although I may be wrong.
If anyone has any insight, it would be appreciated.
Hi, this has been resolved in the original post. The solution is also pasted here below. DRay
widget.on('render', function (widget, event) { // Define how each value series is used var displaySeriesIndex = 0, labelSeriesIndex = 1; // Define where to put the center line var centerLineValue = 0; // Get a reference to the highcharts object var chart = widget.queryResult; // Define a centerline to add to the chart var plotline = { color: 'black', dashStyle: 'solid', width: 2, value: centerLineValue } // Add the center line to the series chart.yAxis[0].plotLines = [plotline]; // Get a reference to the series var displaySeries = chart.series[displaySeriesIndex], labelSeries = chart.series[labelSeriesIndex]; // Loop through each data point in then display series displaySeries.data.forEach(function (data, index) { // Save a reference to the label value data.labelValue = labelSeries.data[index].y; }) // Remove the label series chart.series.splice(labelSeriesIndex, 1); // Get a reference to the sisense formatter var numberFormatter = prism.$injector.get('$filter')('numeric'); // Get a reference to the formatting mask of the label's series var mask = $$get(widget.metadata.panel('values').items[labelSeriesIndex], 'format.mask', {}); // Override the label formatter function chart.plotOptions.bar.dataLabels.formatter = function () { // Use the formatting of the label series, in order to create the value label var newLabel = numberFormatter(this.point.options.labelValue, mask); return newLabel; } })