While attempting to display graphs on a popup, I encountered an issue where the labels were overlapping. I experimented with running the rendering code inside both $(document).ready()
and $(window).load()
, but unfortunately, neither approach resolved the problem.
Ultimately, I discovered that triggering the rendering function on a click event solved the issue.
$(document).ready(function()
{
$('.view_graphs').click(function(){
setTimeout(function(){
renderGraph();
},500)
})
})
function renderGraph() {
google.charts.setOnLoadCallback(column_chart);
function column_chart() {
var data = new google.visualization.arrayToDataTable(<?php echo $visitlang_json_data ?>);
var chart = new google.visualization.ColumnChart(document.getElementById('visit_lang_chart'));
var options = {'title':'Report based on language',
'width':600,
'height':500
};
chart.draw(data,options);
}
}
Implementing a setTimeout
function within the click event handler successfully resolved the overlapping label issue for me.