This example demonstrates a Donut chart with custom labels defined via JavaScript Code.
JavaScript Code - Use this chart-level attribute to define a JavaScript function, to customize the chart attributes and data, allowing you to extend your chart to incorporate attributes not declaratively available in Oracle Application Express. The code used in this example is as follows:
function( options ){
// Create a data label function that takes a dataContext argument. The dataContext contains information on the data item,
// including id, series, group, value, data, seriesData, groupData and component. The function should return the desired data label string or number.
this.donutSliceLabel = function( dataContext ){
var series_name,
percent = Math.round( dataContext.value/dataContext.totalValue*100 );
if ( dataContext.seriesData ) {
series_name = dataContext.seriesData.name;
} else {
// NOTE: when defining an 'Other' segment, there is no associated entry in dataContext.seriesData for that new segment
// Ensure a default label 'Other' is defined in this instance.
series_name = 'Other';
}
return series_name + " " + percent + "% ( " + dataContext.value + " )";
}
// Pass the data label function to the chart dataLabel attribute.
// dataLabel: A JET function that returns a custom data label. The function takes a dataContext argument, provided by the chart.
// Review API guide for details: http://www.oracle.com/webfolder/technetwork/jet/jsdocs/oj.ojChart.html#dataLabel
options.dataLabel = donutSliceLabel;
return options;
}
Label Position - The series-level attribute is set to Outside Slice, to ensure lengthy labels are visible, and rendered outside the slice of the donut.
For more information on the custom label settings, refer to the Oracle JET Cookbook
Chart: Data Label Callback example.