Markers with text on a Google GeoChart

限于喜欢 提交于 2020-01-05 05:45:08

问题


I'm trying to make a Google GeoChart that should look like this :

But, problem is, I'm not even sure it is possible to mix up markers and text in them.

Right now my code is the following :

google.charts.load('current', {'packages':['geochart']});
google.charts.setOnLoadCallback(drawRegionsMap);

function drawRegionsMap() {

    var data = google.visualization.arrayToDataTable([
        ['Region', 'Gagnants'],
        ['Alsace', 6], ['Aquitaine', 1], ['Auvergne', 5], ['Basse-Normandie', 2], ['Bourgogne', 1], ['Bretagne', 7], ['Centre', 1], ['Champagne-Ardenne', 0], ['Corse', 9], ['Franche-Comté', 1], ['Haute-Normandie', 0], ['Île-de-France', 7], ['Languedoc-Roussillon', 0], ['Limousin', 7], ['Lorraine', 1], ['Midi-Pyrénées', 2], ['Nord-Pas-de-Calais', 53], ['Pays de la Loire', 7], ['Picardie', 0], ['Poitou-Charentes', 1], ['Provence-Alpes-Côte d\'Azur', 10], ['Rhône-Alpes', 21]
    ]);

    var options = {region: "FR",
        resolution: "provinces",
        colorAxis: {colors: ['#FFF9F7', '#FC4C13']}
    };

    var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));

    chart.draw(data, options);
}

Which gives me that :

And that's pretty far from what I want. I thought about giving up on google's api and creating a big div holding the raw map as background, and create the markers as text block to positition them right above the corresponding region and set the red marker as background. But it will be the devil's own work to make it look good on every sizes of screens...

Any ideas? Thanks ! :)


回答1:


You could use the Google Maps JavaScript API to add custom markers or markers with labels. Note that the latter is not part of the Google Maps API.

But all of this is probably overkill, I'd rather live with the fact that numbers are visible when hovering each region.

If you also want to highlight each region in a different shade (depending on numbers) you'd need to draw polygons and Google doesn't provide their geometry in any way TMK, so you'd need to get those geometries from somewhere else.



来源:https://stackoverflow.com/questions/39145271/markers-with-text-on-a-google-geochart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!