So I recently encountered a problem where I load both ArcGIS scripts and Google Charts scripts. I'm building out a website where I need both to work on the same page. However, I haven't been able to come up with a solution.
My code is simple and as follows:
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://js.arcgis.com/4.23/" defer></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="sankey_basic" style="width: 900px; height: 300px;"></div>
<script>
$(document).ready(function(){
google.charts.load('current', {'packages':['sankey']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'From');
data.addColumn('string', 'To');
data.addColumn('number', 'Weight');
data.addRows([
[ 'A', 'X', 5 ],
[ 'A', 'Y', 7 ],
[ 'A', 'Z', 6 ],
[ 'B', 'X', 2 ],
[ 'B', 'Y', 9 ],
[ 'B', 'Z', 4 ]
]);
// Sets chart options.
var options = {
width: 600,
};
// Instantiates and draws our chart, passing in some options.
var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
chart.draw(data, options);
}
});
</script>
I set up a CodePen at https://codepen.io/bryant-essense/pen/YzeZrOp, https://codepen.io/bryant-essense/pen/YzeZrOp to replicate the problem.
Notice the "d3.sankey is not a function" message however when you remove or uncomment the ArcGIS script file, Google Charts work correctly, is there a workaround for this?
When I pull in a random ArcGIS chart it looks like both scripts (ArcGIS and Google Charts) are pulling in d3.js libraries,
The console produces the following errors:
Looking further into the issue I come across this link: https://community.esri.com/t5/arcgis-api-for-javascript-questions/multipledefine-error-in-dojoloader/td-p/714961.
Seems we can assign aliases, I'm very unfamiliar with the dojo.js library and modules so any help with this matter is appreciated!