Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Geochart: custom display name using lat/long markers and both values

I have a Google Geochart with the following columns:

// Lat, Long, Value 1, Value 2
[-22.764042,  -43.39921  , 2.86, 1],
[-22.755635,  -43.460325 , 3.70, 2],
[-22.912897,  -43.200295 , 0.50, 1],
[-22.805776 , -43.37292 ,  6.67, 2],
[-23.532905 , -46.63952 ,  33.33, 5]
// ...many rows

I've checked the other answers, but they don't work here.

I can't use those value columns to display a label because both are important on this chart.

I can't use addresses instead of lat/long because it is really, really slow to load all markers (and they are many in the real chart).

I've tried to apply formatters to solve this, but it seems they are overridden by the library which display a "beautiful"coordinate (22º76'4042"S, 43º39'921"W instead of -22.764042, -43.39921)

Is there any way I could load the chart markers with coordinates, but display a custom label on their tooltips?

like image 403
Alan Willms Avatar asked Jan 16 '14 11:01

Alan Willms


1 Answers

You can add a "string" type column after the lat/long columns to give the data point a label for the tooltips:

var data = new google.visualization.DataTable();
data.addColumn('number', 'Latitude');
data.addColumn('number', 'Longitude');
data.addColumn('string', 'Label');
data.addColumn('number', 'Value 1');
data.addColumn('number', 'Value 2');

data.addRows([
    [-22.764042, -43.39921, 'Foo', 2.86, 1],
    [-22.755635, -43.460325, 'Bar', 3.70, 2],
    [-22.912897, -43.200295, 'Baz', 0.50, 1],
    [-22.805776, -43.37292, 'Cad', 6.67, 2],
    [-23.532905, -46.63952, 'Qud', 33.33, 5]
]);

See example here: http://jsfiddle.net/asgallant/GKmm5/

like image 98
asgallant Avatar answered Oct 19 '22 22:10

asgallant