points = [],
regionP,
regionVal,
regionI = 0,
countryP,
countryI,
causeP,
causeI,
region,
country,
cause,
causeName;
Highcharts.setOptions({
colors: [
'#2f7ed8',
'#808080',
'#a6c96a',
'#c42525',
'#77a1e5',
'#f28f43',
'#E000E0',
'#1aadce',
'#910000',
'#41FF32',
'#0d233a',
'#800000',
'#FFBF18']
});
for (region in data) {
if (data.hasOwnProperty(region)) { // con il metodo hasOwnProperty controllo che nella variabile data ci sia 'region'
regionVal = 0; // azzoero il valore del livello più alto ogni volta che cambio region
regionP = {
id: 'id_' + regionI,
name: region,
color: Highcharts.getOptions().colors[regionI]
};
countryI = 0;
for (country in data[region]) {
if (data[region].hasOwnProperty(country)) {
countryP = {
id: regionP.id + '_' + countryI,
name: country,
parent: regionP.id
};
points.push(countryP); // con il metodo Push aggiungo alla variabile Point il valore countryP
causeI = 0;
for (cause in data[region][country]) {
if (data[region][country].hasOwnProperty(cause)) {
causeP = {
id: countryP.id + '_' + causeI,
name: cause,
parent: countryP.id,
value: Math.round(+data[region][country][cause]) // arrotondo il valore a intero
};
regionVal += causeP.value; // somma dei valori del terzo livello
points.push(causeP); // metto i valori su un vettore
causeI = causeI + 1; // incremento l'indice di cause
}
} // quando esco dal for ho regionVal che è la somma delle sotto cause
countryI = countryI + 1; // incremento indice Country
}
}
regionP.value = regionVal;
//regionP.value = Math.round(regionVal/countryI);
points.push(regionP);
regionI = regionI + 1;
}
}
Highcharts.chart('container7', {
series: [{
type: 'treemap',
layoutAlgorithm: 'squarified',
allowDrillToNode: true,
animationLimit: 1000,
dataLabels: {
enabled: false
},
levelIsConstant: false,
levels: [{
level: 1,
dataLabels: {
enabled: true
},
borderWidth: 3
}],
data: points
}],
subtitle: {
text: ''
//text: 'Click points to drill down. Source: WHO .'
},
title: {
text: ''
//text: 'Rendiconto 2015 ( Missioni > 10 Mln)'
},
credits: {
enabled: false
},
tooltip:{
valueSuffix: ' €',
style: {
fontSize: '10px'
}
}
});