public static function geoChart($title, $element_label, $data)
{
$id = Laralum::randomString();
$countries = Laralum::countries();
$default_color = Laralum::settings()->header_color;
// Get the max / min index
$max = 0;
$min = $data[0][1];
foreach ($data as $dta) {
if ($dta[1] > $max) {
$max = $dta[1];
} elseif ($dta[1] < $min) {
$min = $dta[1];
}
}
if (Laralum::settings()->geo_chart_source == 'highcharts') {
$graph = "\n <script type='text/javascript'>\n \$(function () {\n\n // Initiate the chart\n \$('#{$id}').highcharts('Map', {\n\n title : {\n text : '{$title}'\n },\n\n mapNavigation: {\n enabled: true,\n enableDoubleClickZoomTo: true\n },\n\n colorAxis: {\n min: {$min},\n minColor: '#E0E0E0',\n max: {$max},\n maxColor: '{$default_color}',\n },\n\n series : [{\n data : [";
foreach ($data as $dta) {
$e = $dta[0];
$v = $dta[1];
$graph .= "{'code': '{$e}', 'value': {$v}},";
}
$graph .= "\n ],\n mapData: Highcharts.maps['custom/world'],\n joinBy: ['iso-a2', 'code'],\n name: '{$element_label}',\n states: {\n hover: {\n color: '#BADA55'\n }\n },\n }]\n });\n });\n </script>\n <div id='{$id}'></div>\n ";
} else {
$graph = "\n <script type='text/javascript'>\n google.charts.setOnLoadCallback(drawRegionsMap);\n\n function drawRegionsMap() {\n\n var data = google.visualization.arrayToDataTable([\n ['Country', '{$element_label}'],\n ";
foreach ($data as $dta) {
$e = $countries[$dta[0]];
$v = $dta[1];
$graph .= "['{$e}', {$v}],";
}
$graph .= "\n ]);\n\n var options = {\n colorAxis: {colors: ['#E0E0E0', '{$default_color}']},\n datalessRegionColor: '#e0e0e0',\n defaultColor: '#e0e0e0',\n };\n\n var chart = new google.visualization.GeoChart(document.getElementById('{$id}'));\n\n chart.draw(data, options);\n }\n </script>\n <center><b style='font-size: 18px;'>{$title}</b><br><br></center>\n <div id='{$id}'></div>\n ";
}
return $graph;
}