Chart widgets

Chart widgets are configured in the type chartWidget or one of its subitems. They use the Highcharts library. All attributes are JSON objects.

The following figure shows the default chart widget with the number of cases in the current view:

You can provide settings both in the widget script and in the widget settings. The values set in the script overwrite the values entered in the widget settings.

General attributes:

Highcharts attributes:

See https://api.highcharts.com/highcharts/ for details about the available Highcharts attributes.

Coding example

The following example shows the script which is used for the default chart widget showing the number of cases in the current view. The script has to return a HashMap containing the attributes which should be set.

import com.consol.cmas.common.model.ticket.*;

import com.consol.cmas.common.model.ticket.view.*;

import java.util.*;

import java.util.Map.Entry;

 

if (viewId == -1) {

return [visible: 'false']

}

 

def engineerLocale = engineerService.getCurrentLocale()

def view = viewService.getById(viewId)

def viewName = localizationService.getLocalizedProperty(View.class, "name", viewId, engineerLocale)

 

ViewCriteria allCriteria = new ViewCriteria(view,

ViewAssignmentParameter.allTickets(),

ViewGroupParameter.allTickets(),

new ViewOrderParameter())

 

 

def allTickets = ticketService.getCountForView(allCriteria)

 

 

ViewCriteria ownCriteria = new ViewCriteria(view,

ViewAssignmentParameter.allTickets(engineerService.getCurrent()),

ViewGroupParameter.onlyOwnTickets(),

new ViewOrderParameter())

 

def ownTickets = ticketService.getCountForView(ownCriteria)

 

ViewCriteria unassignedCriteria = new ViewCriteria(view,

ViewAssignmentParameter.allUnassignedTickets(),

ViewGroupParameter.onlyUnassignedTickets(),

new ViewOrderParameter())

 

def unassignedTickets = ticketService.getCountForView(unassignedCriteria)

 

 

def data = []

 

data.add("{name: _('all'), data:[${allTickets}]}" as String)

data.add("{name: _('own'), data:[${ownTickets}]}"as String)

data.add("{name: _('unassigned'), data:[${unassignedTickets}]}"as String)

 

 

return [series: "[${data.join(',')}]" as String,

visible: 'true',

chart: "{type: 'column'}", title: "{text: '${viewName}'}" as String,

tooltip:"{headerFormat:''}" ,

localization:"de: {all:'Alle',own:'Eigene',unassigned:'Unzugewiesene'},"+ "en: {all:'All', own:'Own', unassigned: 'Unassigned'}"];

Code example 36: Script for the default chart widget ticketsInViewDataWidget.groovy

The type of chart can be modified in the type sub-attribute of the chart attribute. There is a large number of available chart types, see https://api.highcharts.com/highcharts/plotOptions.

The following figure shows a chart of the type funnel:

The following code example demonstrates the basic principle of the implementation of a funnel widget. Some static data is used for demo purposes.

return [title: "{text: _('title')}",

chart: "{type: 'funnel', \

marginLeft: '50', \

marginRight: '150'}",

plotOptions: "{series:{ height: '90%', \

width: '85%', \

neckWidth: '20%', \

neckHeight: '20%', \

dataLabels: {enabled:'true', \

format: '<b>{point.name}</b> ({point.y:,.0f})', \

softConnector: 'true'}}}",

visible: "true",

series: "[{name: _('users'), \

data: [[_('visits') , 15654], \

[_('downloads'), 4064], \

[_('requests') , 1987]]}]",

localization: "de: {title: 'Vertriebstrichter', \

users: 'Individuelle Benutzer', \

visits: 'Seitenaufrufe', \

downloads: 'Downloads', \

requests: 'Anfrage Preisliste'}, \

en: {title: 'Salesfunnel', \

users: 'Unique users', \

visits: 'Page visits', \

downloads: 'Downloads', \

requests: 'Requests for price list'}"

]

Code example 37: Script for a sales funnel chart with demo data