Closed alangularte closed 10 years ago
I solved it changinfg the way I call PHP file:
map = new Datamap({ element: document.getElementById("map"), projection: 'mercator', fills: { defaultFill: "#CCC", countryColor: "#fa0fa0" }, dataUrl: 'data/search.php', dataType: 'json', data: {} });
Cool! Does it all work with the dataUrl
?
Yes, just perfect!
My PHP sample:
$data = Array(); $data["USA"]["fillKey"] = "#fa0fa0"; $data["USA"]["numberOfThings"] = "12";
$data["ARG"]["fillKey"] = "#fa0fa0"; $data["ARG"]["numberOfThings"] = "12";
$json = json_encode($data);
echo $json;
I just created an Array and converted it to JSON, sending it back to my JS script by ECHO.
JS sample:
function updateMap(year){
//Delete actual map
$("#map").empty();
map = new Datamap({
element: document.getElementById("map"),
projection: 'mercator',
fills: {
defaultFill: "#CCC",
countryColor: "#fa0fa0"
},
dataUrl: 'data/search.php?year='+year,
dataType: 'json',
data: {},
geographyConfig: {
popupTemplate: function(geo, data) {
return ['<div class="hoverinfo"><strong>',
'Total of concerts in ' + geo.properties.name,
': ' + data.numberOfThings,
'<a href="":</strong></div>'].join('');
}
},
});
}
Hi all!
How can I send data to datamaps from PHP?
I have this:
PHP is sending:
<?php
$data = Array(); $data["USA"]["fillKey"] = "#fa0fa0"; $data["USA"]["numberOfThings"] = "12";
$json = json_encode($data);
echo $json; ?>
But it's not working.