International comparison of PISA scores

The Program for International Student Assesment (PISA) is an international study conducted by the OECD. It measures the evolution of the performance of 15 years old pupils on mathematics, science and reading in different countries.

This document demonstrates how to use the leaflet.minichart plugin to represent over a leaflet map the scores of the pupils of the different countries.


The data to represent has the following format:

var data = [

We also have the average score for each category:

var avgScores = {math: 493.4, reading: 492.7, science: 498.2};

Initialisation of the map

In the header of our html file we include leaflet and the leaflet.minichart plugin:

<link rel="stylesheet" href="" media="screen" title="leaflet">
<script src="" charset="utf-8"></script>
<script src="../dist/leaflet.minichart.min.js" charset="utf-8"></script>
<script src="" charset="utf-8"></script>

We also add a div that will contain the leaflet map:

<div id="map" style="width:100%;height:400px;"></div>

The following javascript code initializes the map:

var center = [48.861415, 4.349326];
var mymap ='map').setView(center, 4);
var tiles = L.tileLayer('{z}/{y}/{x}');

We now want to add to the map barcharts that represent the deviance to the mean of the three scores for year 2015. To do so, we loop over our data and create a minicharts object for each country. We store store them in an array so we will be able to update them later.

var charts = {};
for (var i = 0; i < data.length; i++) {
  var d = data[i];

  if (d.year == 2015) {
    var scoresDiff = [
      d.math - avgScores.math,
      d.reading - avgScores.reading, -
    charts[] = L.minichart([, d.lon], {data: scoresDiff, maxValues: 90});
    mymap.addLayer(charts[] ) ;

We can improve our map by passing some additional options to L.minichart to reduce the size of the charts and use prettier colors:

charts[] = L.minichart(
  [, d.lon],
    data: scoresDiff,
    maxValues: 90,
    width:40, height:40,
    colors: ["#7A8B99", "#91ADC2", "#A9DDD6"]

Update charts

We have represented the PISA results for 2015 but we would like to also look at the results of the other years. To do so let us add a select input to our document. Each time the user changes the value of the input a javascript function called "updateMap" is

<select id = "year" onchange="updateMap()">
  <option value="2015">2015</option>
  <option value="2012">2012</option>
  <option value="2009">2009</option>
  <option value="2006">2006</option>

To update charts we use the setOption method.

function updateMap() {
  var year = document.getElementById("year").value;
  for (var i = 0; i < data.length; i++) {
    var d = data[i];

    if (d.year == year) {
      var scoresDiff = [
        d.math - avgScores.math,
        d.reading - avgScores.reading, -

Here is the final result: