Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't all the provinces of Pakistan get colored green?

I want to include all the provinces of Pakistan using google geochart. But only 3 are picked up. My code is setting the names of provinces in the script and then the provinces should get picked up by the library.

var data = google.visualization.arrayToDataTable([
    ['Province'],
    ['Punjab'],
    ['Khyber Pakhtunkhwa'],
    ['Islamabad Capital Territory'],
    ['Federally Administered Tribal Areas'],
    ['Northern Areas'],
    ['Azad Kashmir'],
    ['Balochi']
]);

One possibility is that I spellt the regions wrong but it doesn't seem that way.

 <!DOCTYPE html>
<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="keywords"
          content="Houses Apartments, Vacation homes, Offices, Land, Flatmates,Paying Guest, Other real estate, Cars, Motorcycles, Accessories  parts, Trucks, Other vehicles, Home  Garden, Clothing, For Kids (Toys  Clothes), Jewelry  Watches, Hobbies, Sports  Bicycles, Movies, Books  Magazines, Pets, Tickets, Art  Collectibles, Music  Instruments, Computers  Accessories, TV, Audio, Video, Cameras, Cellphones  gadgets, Video games  consoles, Job offers, Resumes, Services, Classes, Professional,Office equipment, Other,  ">
    <meta name="description"
          content="Find jobs, cars, houses, mobile phones and properties for sale in your region conveniently. Find the best deal among {{count}} free ads online!">

    <title>Free classifieds in India - Koolbusiness.com</title>

    <link href="/static/css/koolindex_in.css?0.238133053892" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/static/js/jquery-1.10.2.min.js?0.238133053892"></script>
</head>
<body>
{% include "kooltopbar.html" %}

    <script type='text/javascript' src='http://www.google.com/jsapi'></script>
    <script type='text/javascript'>


        function drawMap() {
 var data = google.visualization.arrayToDataTable([
           ['Province'],
         ['Punjab'],
        ['Khyber Pakhtunkhwa'],
         ['Islamabad Capital Territory'],
          ['Federally Administered Tribal Areas'],
        ['Northern Areas'],
         ['Azad Kashmir'],
        ['Balochi']
    ]);

 var options = {
           region:'PK',
          backgroundColor: '#81d4fa',
          datalessRegionColor: '#ffc801',
      width:468,
       height:278,
     resolution: 'provinces',
        };
    var container = document.getElementById('mapcontainer');
    var chart = new google.visualization.GeoChart(container);

    function myClickHandler(){
        var selection = chart.getSelection();
        var message = '';
        for (var i = 0; i < selection.length; i++) {
            var item = selection[i];
           // if (item.row != null && item.column != null) {
                message += '{row:' + item.row + ',column:' + item.column + '}';
            //} else
             if (item.row != null) {
                message += '{row:' + item.row + '}';
            //} else if (item.column != null) {
              //  message += '{column:' + item.column + '}';
            }
        }
        if (message == '') {
            message = 'nothing';
        }
        //alert('You selected ' + message);

        if (item.row==2) {
             window.location = "/andhra_pradesh/";
        }
        if (item.row==3) {
             window.location = "/arunachal_pradesh/";
        }
        if (item.row==4) {
             window.location = "/assam/";
        }
        if (item.row==6) {
             window.location = "/chhattisgarh/";
        }
        if (item.row==7) {
             window.location = "/goa/";
        }
        if (item.row==8) {
             window.location = "/gujarat/";
        }
        if (item.row==9) {
             window.location = "/haryana/";
        }
        if (item.row==10) {
             window.location = "/himachal_pradesh/";
        }
        if (item.row==11) {
             window.location = "/jammu_kashmir/";
        }
        if (item.row==12) {
             window.location = "/jharkhand/";
        }
        if (item.row==13) {
             window.location = "/karnataka/";
        }
        if (item.row==14) {
             window.location = "/kerala/";
        }
        if (item.row==15) {
             window.location = "/madhya_pradesh/";
        }
        if (item.row==16) {
             window.location = "/maharashtra/";
        }
        if (item.row==17) {
             window.location = "/manipur/";
        }
        if (item.row==18) {
             window.location = "/meghalaya/";
        }
        if (item.row==19) {
             window.location = "/mizoram/";
        }
        if (item.row==20) {
             window.location = "/nagaland/";
        }
        if (item.row==21) {
             window.location = "/orissa/";
        }
        if (item.row==22) {
             window.location = "/punjab/";
        }
        if (item.row==23) {
             window.location = "/rajasthan/";
        }
        if (item.row==24) {
             window.location = "/sikkim/";
        }
        if (item.row==25) {
             window.location = "/tamil_nadu/";
        }
        if (item.row==25) {
             window.location = "/tripura/";
        }
        if (item.row==28) {
             window.location = "/uttar_pradesh/";
        }
        if (item.row==29) {
             window.location = "/west_bengal/";
        }
        if (item.row==36) {
             window.location = "/andaman_nicobar_islands/";
        }
    }
    google.visualization.events.addListener(chart, 'select', myClickHandler);
    chart.draw(data, options);
        }
google.load('visualization', '1', {packages: ['geochart'], callback: drawMap});

     </script>

<div id="wrapper">

<!--[if lt IE 7]>
<div class="alert-outer alert-error">
    <a href="#" class="alert-closer" title="close this alert" onclick="removeIeNotification(this); return false;">×</a>

    <div class="alert-inner">
        <span><strong>You are using an outdated version of Internet Explorer.</strong> For a faster, safer browsing experience, upgrade today!</span>

    </div>
</div>
![endif]-->
<header>


    <h1 id="logo" class="sprite_index_in_in_en_logo spritetext">koolbusiness.com - The right choice for buying &amp;
        selling in Pakistan</h1>

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- v2 -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:15px"
         data-ad-client="ca-pub-7211665888260307"
         data-ad-slot="9119838994"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
</header>

<![endif]-->
<div style="width: 100%; overflow: hidden;">
    <div style="width: 768px; float: left;"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- front leaderboard -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-7211665888260307"
     data-ad-slot="4543980997"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script> </div>
    <div id="post3" style="margin-left: 735px;"> <a href="/ai" id="ad2">Post your ad for free</a> </div>
</div>


<div class="main">
<div class="column_left">
    <div class="box">

        <ul>
            <li>KoolBusiness is easy, free, and kool.</li>
            <li>Buy and sell <a href="/Pakistan/cars-for_sale">cars</a>, check our <a href="/Pakistan/real_estate">real
                estate</a>
                section, find <a href="/Pakistan/jobs">jobs</a>, and much more.
            </li>
            <li>Check our <strong><a href="/Pakistan">{{count}} ads online</a></strong> and find what you are looking for
                in
                your region or in all Pakistan.
            </li>
        </ul>


    </div>

    <div id="regions">


        <div class="region_links_one">
            <ul class="regions_one">
                <li><a id="region_8" class="region" href="http://www.koolbusiness.com/andhra_pradesh/">Andhra
                    Pradesh</a></li>
                <li><a id="region_9" class="region" href="http://www.koolbusiness.com/arunachal_pradesh/">Arunachal
                    Pradesh</a></li>
                <li><a id="region_10" class="region"
                       href="http://www.koolbusiness.com/assam/">Assam</a>
                </li>
                <li><a id="region_11" class="region"
                       href="http://www.koolbusiness.com/bihar/">Bihar</a>
                </li>
                <li><a id="region_12" class="region"
                       href="http://www.koolbusiness.com/chhattisgarh/">Chhattisgarh</a></li>
                <li><a id="region_13" class="region"
                       href="http://www.koolbusiness.com/goa/">Goa</a></li>
                <li><a id="region_14" class="region" href="http://www.koolbusiness.com/gujarat/">Gujarat</a>
                </li>
                <li><a id="region_15" class="region" href="http://www.koolbusiness.com/haryana/">Haryana</a>
                </li>
                <li><a id="region_16" class="region" href="http://www.koolbusiness.com/himachal_pradesh/">Himachal
                    Pradesh</a></li>
                <li><a id="region_17" class="region" href="http://www.koolbusiness.com/jammu_kashmir/">Jammu
                    &amp;
                    Kashmir</a></li>
                <li><a id="region_18" class="region" href="http://www.koolbusiness.com/jharkhand/">Jharkhand</a>
                </li>
                <li><a id="region_19" class="region" href="http://www.koolbusiness.com/karnataka/">Karnataka</a>
                </li>
                <li><a id="region_20" class="region" href="http://www.koolbusiness.com/kerala/">Kerala</a>
                </li>
                <li><a id="region_21" class="region" href="http://www.koolbusiness.com/madhya_pradesh/">Madhya
                    Pradesh</a></li>
            </ul>
            <ul class="regions_two">
                <li><a id="region_22" class="region"
                       href="http://www.koolbusiness.com/maharashtra/">Maharashtra</a></li>
                <li><a id="region_23" class="region" href="http://www.koolbusiness.com/manipur/">Manipur</a>
                </li>
                <li><a id="region_24" class="region" href="http://www.koolbusiness.com/meghalaya/">Meghalaya</a>
                </li>
                <li><a id="region_25" class="region" href="http://www.koolbusiness.com/mizoram/">Mizoram</a>
                </li>
                <li><a id="region_26" class="region" href="http://www.koolbusiness.com/nagaland/">Nagaland</a>
                </li>
                <li><a id="region_27" class="region" href="http://www.koolbusiness.com/orissa/">Orissa</a>
                </li>
                <li><a id="region_28" class="region" href="http://www.koolbusiness.com/punjab/">Punjab</a>
                </li>
                <li><a id="region_29" class="region" href="http://www.koolbusiness.com/rajasthan/">Rajasthan</a>
                </li>
                <li><a id="region_30" class="region" href="http://www.koolbusiness.com/sikkim/">Sikkim</a>
                </li>
                <li><a id="region_31" class="region" href="http://www.koolbusiness.com/tamil_nadu/">Tamil
                    Nadu</a></li>
                <li><a id="region_32" class="region" href="http://www.koolbusiness.com/tripura/">Tripura</a>
                </li>
                <li><a id="region_34" class="region"
                       href="http://www.koolbusiness.com/uttaranchal/">Uttaranchal</a></li>
                <li><a id="region_33" class="region" href="http://www.koolbusiness.com/uttar_pradesh/">Uttar
                    Pradesh</a></li>
                <li><a id="region_35" class="region" href="http://www.koolbusiness.com/west_bengal/">West
                    Bengal</a></li>
            </ul>
        </div>
        <div class="region_links_two">
            <!-- ads here -->
            <h2>Union territories</h2>


            <ul class="regions_one">
                <li><a class="region" href="http://www.koolbusiness.com/delhi/">Delhi</a></li>
                <li><a class="region" href="http://www.koolbusiness.com/lakshadweep/">Lakshadweep</a></li>
                <li><a class="region" href="http://www.koolbusiness.com/daman_diu/">Daman &amp; Diu</a>
                </li>
                <li><a class="region" href="http://www.koolbusiness.com/dadra_nagar_haveli/">Dadra &amp; Nagar
                    Haveli</a>
                </li>
            </ul>
            <ul class="regions_two">
                <li><a class="region" href="http://www.koolbusiness.com/chandigarh/">Chandigarh</a></li>
                <li><a class="region" href="http://www.koolbusiness.com/pondicherry/">Pondicherry</a></li>
                <li><a class="region" href="http://www.koolbusiness.com/andaman_nicobar_islands/">Andaman &amp;
                    Nicobar
                    Islands</a></li>
            </ul>
        </div>
    </div>

</div>
<div id="my_wrapper">

<div id="mapcontainer"></div>
<div id="gads" style="clear:both">

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- frontpagebelowmap -->
<ins class="adsbygoogle"
     style="display:inline-block;width:300px;height:250px"
     data-ad-client="ca-pub-7211665888260307"
     data-ad-slot="3839303791"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>



</div>
</div>



<footer class="nohistory columns">



    <p class="first">A good deal is just around the corner!</p>


    <p>KoolBusiness is the right choice for safe buying and selling in Pakistan: a free classifieds website where you
        can buy and sell almost everything.</p>


    <p><a href="/ai">Post an ad for free</a> or browse through our categories. You will find thousands of free
        classifieds for cars, houses, mobile phones and gadgets, computers, pets and dozens of items and services in
        your state or union territory.</p>


    <p>

        <strong>KoolBusiness does not charge any fee and does not require registration.</strong> Every
        ad is checked so we can give you the highest quality possible for the ads on our site. That’s why
        KoolBusiness is the most convenient, easiest to use and most complete free ads site in Pakistan.</p>


    <div id="world_sites">





    </div>




</footer>

</div>



</body>
</html>

enter image description here

like image 699
Niklas Rosencrantz Avatar asked Apr 06 '15 06:04

Niklas Rosencrantz


3 Answers

Apparently the region names used by visualization API are somewhat incorrect (e.g. Sindh is referenced as Sind in the API). However, the most recent ISO 3166 country + subdivision codes seem to work where the names don't. Here is the complete map for Pakistan:

function drawMap() {
  var data = google.visualization.arrayToDataTable([
    ['Province'],
    ['Federally Administered Tribal Areas'],
    ['Islamabad'],
    ['Punjab'],
    ['PK-KP'], // North West Frontier
    ['Azad Kashmir'],
    ['PK-GB'], // Northern Areas
    ['Baluchistan'],
    ['Sind']
  ]);
  var options = {
    region: 'PK',
    backgroundColor: '#81d4fa',
    datalessRegionColor: '#ffc801',
    width: 468,
    height: 278,
    resolution: 'provinces',
  };
  var container = document.getElementById('mapcontainer');
  var chart = new google.visualization.GeoChart(container);
  chart.draw(data, options);
}
google.load('visualization', '1', {
  packages: ['geochart'],
  callback: drawMap
});
<script type='text/javascript' src='http://www.google.com/jsapi'></script>
<div id="mapcontainer" style="height: 500px;"></div>
like image 144
Salman A Avatar answered Nov 02 '22 00:11

Salman A


As stated by Google Charts developer docs, it is not supported for all countries (if you try this for US, you will see it is working, although I could not make it paint Alabama. If you try Canada, Ontario is not painted).

resolution: 'provinces' - Supported only for country regions and US state regions. Not supported for all countries; please test a country to see whether this option is supported.

like image 10
Ivan Jovović Avatar answered Nov 01 '22 22:11

Ivan Jovović


Those 3 provinces don't have a space in their name. Hope this might help.

like image 3
Thirupathi Thangavel Avatar answered Nov 02 '22 00:11

Thirupathi Thangavel