1

I'm trying to create a mapping website for my thesis. I got this sample from high-maps, and it works.

// Prepare random data
var data = [
    ['DE.SH', 728],
    ['DE.BE', 710],
    ['DE.MV', 963],
    ['DE.HB', 541],
    ['DE.HH', 622],
    ['DE.RP', 866],
    ['DE.SL', 398],
    ['DE.BY', 785],
    ['DE.SN', 223],
    ['DE.ST', 605],
    ['DE.NW', 237],
    ['DE.BW', 157],
    ['DE.HE', 134],
    ['DE.NI', 136],
    ['DE.TH', 704],
    ['DE.', 361]
];

$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=germany.geo.json&callback=?', function (geojson) {

    // Initiate the chart
    Highcharts.mapChart('container', {

        title: {
            text: 'GeoJSON in Highmaps'
        },

        mapNavigation: {
            enabled: true,
            buttonOptions: {
                verticalAlign: 'bottom'
            }
        },

        colorAxis: {
            tickPixelInterval: 100
        },

        series: [{
            data: data,
            mapData: geojson,
            joinBy: ['code_hasc', 0],
            keys: ['code_hasc', 'value'],
            name: 'Random data',
            states: {
                hover: {
                    color: '#a4edba'
                }
            },
            dataLabels: {
                enabled: true,
                format: '{point.properties.postal}'
            }
        }]
    });
});
#container {
    height: 500px; 
    min-width: 310px; 
    max-width: 800px; 
    margin: 0 auto; 
}
.loading {
    margin-top: 10em;
    text-align: center;
    color: gray;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>


<div id="container" style="min-width: 310px; max-width: 400px"></div>

I have a map file which is located in my local data, so I want to change the existing map with mine and also change the random data. I try to change the $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=germany.geo.json&callback=?', function (geojson) with $.getJSON('3312kec.geojson', function (geojson).

// Prepare random data
var data = [
    ['010', 728],
    ['020', 710],
    ['030', 963],
    ['040', 541],
    ['050', 622],
    ['060', 866],
    ['070', 398],
    ['080', 785],
    ['090', 223],
    ['100', 605],
    ['110', 237],
    ['120', 157],
    ['130', 134],
    ['140', 136],
    ['150', 704],
   ['160', 398],
    ['170', 785],
    ['180', 223],
    ['190', 605],
    ['200', 237],
    ['201', 157],
    ['210', 134],
    ['220', 136],
    ['230', 704],
    ['240', 361]
];

$.getJSON('3312kec.geojson', function (geojson) {

    // Initiate the chart
    Highcharts.mapChart('container', {

        title: {
            text: 'GeoJSON in Highmaps'
        },

        mapNavigation: {
            enabled: true,
            buttonOptions: {
                verticalAlign: 'bottom'
            }
        },

        colorAxis: {
            tickPixelInterval: 100
        },

        series: [{
            data: data,
            mapData: geojson,
            joinBy: ['code_hasc', 0],
            keys: ['code_hasc', 'value'],
            name: 'Random data',
            states: {
                hover: {
                    color: '#a4edba'
                }
            },
            dataLabels: {
                enabled: true,
                format: '{point.properties.postal}'
            }
        }]
    });
});
#container {
    height: 500px; 
    min-width: 310px; 
    max-width: 800px; 
    margin: 0 auto; 
}
.loading {
    margin-top: 10em;
    text-align: center;
    color: gray;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>


<div id="container" style="min-width: 310px; max-width: 400px"></div>

I have tried various ways but always failed. Is there someone who can help me?

  • Are you running some kind of webserver locally? If not, you'll have an issue, see [this post](https://stackoverflow.com/questions/19902538/loading-local-files-with-javascript-without-a-web-server). – Nick Oct 14 '17 at 03:30
  • Thanks for answering my question. Yes, I run it locally using XAMPP. – Rizky Rindi Arumingdien Oct 14 '17 at 04:44

0 Answers0