Let me show you with an example. Let´s say you want to use the library echarts.js.
I would do this way:
1- add the library to an ui_template node configuring in to be added to the <head>
section of the site.
2- In you template node you can use the methods provided by the library inside script tags.
<script type="text/javascript">
var dom = document.getElementById("divChart3");
var myChart =null;
myChart = echarts.init(dom);
option = null;
{{{payload}}}
if (option && typeof option === "object")
{
myChart.setOption(option, true);
}
</script>