Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQVMap - How to show data values onregionclick

var setMap = function (name) {
        var data = {
            map: 'world_en',
            backgroundColor: null,
            borderColor: '#333333',
            borderOpacity: 0.5,
            borderWidth: 1,
            color: '#c6c6c6',
            enableZoom: true,
            hoverColor: '#c9dfaf',
            hoverOpacity: null,
            values: sample_data,
            normalizeFunction: 'linear',
            scaleColors: ['#b6da93', '#909cae'],
            selectedColor: '#c9dfaf',
            selectedRegion: null,
            showTooltip: true,
            onLabelShow: function (event, label, code) {

            },
            onRegionOver: function (event, code) {
                if (code == 'ca') {
                    event.preventDefault();
                }
            },
            onRegionClick: function (element, code, region) {
                var message = 'You clicked "' + region + '" which has the code: ' + code.toUpperCase();
                alert(message);
            }
        };

        data.map = name + '_en';
        var map = jQuery('#vmap_' + name);
        map.width(map.parent().parent().width());
        map.show();
        map.vectorMap(data);
        map.hide();
    }

Anyone knows how to use the values of the clicked region in the onRegionClick function? I use this map to provide website statistics and want to alert on click something like "1000 Views in US (United States)"

like image 511
malifa Avatar asked Feb 15 '13 12:02

malifa


1 Answers

As i said in my comment, i found out the solution right after i asked the question, but for those who have this little problem, too i just post my solution. You just have to append the string you want to display to the label.

onLabelShow: function (event, label, code) {
    if(sample_data[code] > 0)
        label.append(': '+sample_data[code]+' Views'); 
}

hope it helps.

like image 151
malifa Avatar answered Nov 10 '22 10:11

malifa