Problem with embedding Google Charts with a Scriptrunner Custom Field

I have created a custom field that outputs a google chart based on some data from the issue. This works so far, but there is a side effect, that I cannot browse issues anymore, as soon as an issue is selected that contains the chart. The UI looks deactivated (see screenshot).

I guess it has something to do with the javascript from google, but I don't know how to solve this. Any ideas?

 

Code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def counterToDo = 0
def counterInProgress = 0
def counterDone = 0
def currenIssueStatusCategoryName = ''
def returnstring = ''

/*
Stories directly under the initiative
*/
def queryString = "issueFunction in linkedIssuesOf('issue = " + issue.getKey() + "', 'derives') AND issuetype != Epic"
def query = jqlQueryParser.parseQuery(queryString)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getIssues().each {documentIssue ->
currenIssueStatusCategoryName = documentIssue.getStatus().getStatusCategory().getName()
if (currenIssueStatusCategoryName == "New") {
counterToDo += 1
} else if (currenIssueStatusCategoryName == "In Progress") {
counterInProgress += 1
} else if (currenIssueStatusCategoryName == "Complete") {
counterDone += 1
} // end if
} // end each

/*
Stories in epics
*/
queryString = "issueFunction in linkedIssuesOf('issue = " + issue.getKey() + "', 'derives') AND issuetype = Epic"
query = jqlQueryParser.parseQuery(queryString)
results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
def epicString = ''

if (results.total > 0) {
results.getIssues().each {documentIssue ->
epicString += documentIssue.getKey() + ','
} // end each

queryString = "issueFunction in issuesInEpics ('issuekey IN (" + epicString.substring(0, epicString.length() - 1) + ")')"
query = jqlQueryParser.parseQuery(queryString)
results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getIssues().each {documentIssue ->
currenIssueStatusCategoryName = documentIssue.getStatus().getStatusCategory().getName()
if (currenIssueStatusCategoryName == "New") {
counterToDo += 1
} else if (currenIssueStatusCategoryName == "In Progress") {
counterInProgress += 1
} else if (currenIssueStatusCategoryName == "Complete") {
counterDone += 1
} // end if
} // end each
} // end if

if (counterToDo > 0 || counterInProgress > 0 || counterDone > 0) {
returnstring = """<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script><div id='chart_div'></div>

<script type='text/javascript'>
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic);

function drawBasic() {

var data = google.visualization.arrayToDataTable([
['Status Category', 'ToDo', { role: 'annotation' }, { role: 'style' }, 'In Progress', { role: 'annotation' }, { role: 'style' }, 'Done', { role: 'annotation' }, { role: 'style' }],
['Issues', ${Integer.toString(counterToDo)}, ${Integer.toString(counterToDo)}, '#396886', ${Integer.toString(counterInProgress)}, ${Integer.toString(counterInProgress)}, '#ffd144',${Integer.toString(counterDone)}, ${Integer.toString(counterDone)}, '#008e27']
]);

var options = {
width: '99%',
height: 20,
chartArea: {'width': '100%', 'height': '100%'},
legend: { position: 'none' },
bar: { groupWidth: '100%' },
isStacked: 'relative',
hAxis: { textPosition: 'none', direction: -1,format: 'percent' },
vAxis: { textPosition: 'none' },
annotations: {
textStyle: {
fontSize: 12,
color: '#fff',
opacity: 0.5
}
},
backgroundColor: {
fill: 'transparent'
}
};

var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
var c_div = document.getElementById('chart_div');


chart.draw(data, options);
}


</script>
"""
return returnstring.replaceAll(/ /, '');
} // end if

1 answer

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,316 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot