xxxxxxxxxx
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Highcharts Extract Example</title>
<!-- Code example for class extracted from https://datatools.urban.org/Features/wealth-inequality-charts/ with code from Tim Meko and Ben Chartoff -->
<style>
body {
font: 16px/24px Verdana, Helvetica, Helvetica Neue, Arial;
width: 90%;
}
.aside-content {
background: #f9f9f9;
margin: 20px;
width: 600px;
}
.btn {
display: inline;
font-size: 14px;
padding: 14px;
cursor: pointer;
border: none;
color: white;
background-color: #1696d2;
display: block;
line-height: 12px;
text-transform: uppercase;
text-align: center;
float: left;
margin-right: 1px;
}
.chart {
margin: 0 auto;
margin-top: 0px;
position: relative;
width: 600px;
height: 70%;
}
.btn:hover {
background-color: #000;
}
.clearfix:before,
.clearfix:after {
content: ' ';
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
.hide {
display: none;
}
.show {
display: block;
}
</style>
</head>
<body>
<div class='aside-content'>
<div id='total-mortality' class='chart show'></div>
<div id='gdp-rate' class='chart hide'></div>
<div class='btn-group clearfix'>
<button id='racegap' class='btn autocompare'>Show GDP and Rate Mortality</button>
</div>
<p class='chart-notes'><b>Source:</b> Global Health Observatory (GHO), World Health Organization. World Bank.</p>
<b>Data source:</b> <a href='https://www.who.int/gho/mortality_burden_disease/life_tables/situation_trends/en/'>GHO</a>. <a href="https://data.worldbank.org/">World Bank</a></p>
<p class='chart-notes'><b>Notes:</b> Click on the country names to exclude countries in the analysis, so you can compare those that you prefer.</p>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script type='text/javascript'>
// style theme
colors: ['#0096d2', '#00578b', '#fcb918', '#f47d20', '#6d6d6d', '#c6c6c6', 'rgba(0, 153, 255, 1)',
'#55BF3B', '#DF5353', '#7798BF', '#aaeeee'],
Highcharts.theme = {
chart: {
backgroundColor: null,
style: {
fontFamily: 'Verdana, sans-serif'
},
marginTop: 0,
marginBottom: 40
},
title: {
style: {
fontSize: '18px',
fontWeight: 'bold',
color: '#5a5a5a'
},
align: 'left'
},
subtitle: {
align: 'left'
},
tooltip: {
backgroundColor: 'rgba(229, 231, 234,0.9)',
borderWidth: 0,
borderColor: null,
shape: 'square',
followTouchMove: false,
followPointer: false,
style: {
color: '#000000',
fontWeight: 'normal'
}
},
legend: {
itemMarginBottom: 5,
itemStyle: {
fontSize: '13px',
color: '#5a5a5a',
fontWeight: 'normal'
},
},
exporting: {
enabled: false
},
credits: {
enabled: false
},
xAxis: {
gridLineWidth: 1,
gridLineDashStyle: 'Dash',
gridLineColor: 'rgba(219,219,216,0.5)',
labels: {
style: {
fontSize: '12px'
}
},
tickmarkPlacement: 'on',
tickInterval: 10
},
yAxis: {
gridLineWidth: 1.2,
gridLineDashStyle: 'Dash',
minorTickInterval: 'none',
gridLineColor: 'rgba(219,219,216,0.5)',
title: {
},
labels: {
style: {
fontSize: '12px'
}
}
},
}
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
$(function () {
var processed_json = new Array();
$.getJSON('data.json', function(data) {
// Populate series
for (i = 0; i < data.length; i++){
processed_json.push([data[i].name, data[i].value]);
}
$(function() {
Highcharts.setOptions({
lang: {
thousandsSep: ','
}
});
// 2 charts created
//chart5-mean
$('#total-mortality').highcharts({
chart: {
type: 'line',
marginTop: 120,
marginBottom: 40
},
plotOptions: {
series: {
marker: {
enabled: true,
radius: 3.2,
lineWidth: 0.3,
symbol: 'circle',
fillColor: '#ffffff',
lineColor: null
},
dataLabels: {
enabled: false,
align: 'right',
x: 0,
y: -5,
formatter: function () {
if ((this.point.x == this.series.data.length - 1) || (this.point.x == 0)) {
return Highcharts.numberFormat(this.x, 0, '.', ',');
Highcharts.numberFormat(this.y, 0, '.', ',')
} else {
return null;
}
}
}
}
},
title: {
text: 'Children mortality in South America since 2002'
},
subtitle: {
text: '',
x: 0,
y: 35
},
xAxis: {
gridLineWidth: '',
lineWidth: 0.5,
tickInterval: 2,
categories: ['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013'],
plotLines: [{
value: 0,
width: 0
}],
labels: {
step: 0,
x: 0,
y: 20
}
},
yAxis: {
title: {
text: ''
},
min: 0,
startOnTick: false,
labels: {
format: '{value:,.0f}'
}
},
tooltip: {
shared: false,
formatter: function () {
return this.series.name + '<br>' +
'</b><b>' + Highcharts.numberFormat(this.point.y, 0, ',') + ' children died </b> in ' + this.x;
}
/*formatter: function () {
return '<span style="color:' + this.series.color + '"><b>' + this.series.name + '</b><br/>' + this.y + ' children died in ' + this.x ' k</span>';
}*/
},
credits: {
enabled: false,
text: '',
href: ''
},
legend: {
enabled: true,
floating: 'true',
align: 'center',
verticalAlign: 'left',
layout: 'horizontal',
borderWidth: 0,
itemDistance: 9,
y: 40
},
series: [{
name: 'Infant mortality',
data: processed_json
}); //end chart racial weawlth gap
// this one is hidden by default:
//chart5-median
$(function () {
$('#gdp-rate').highcharts({
chart: {
type: 'scatter',
zoomType: 'xy',
marginTop: 120,
marginBottom: 60
},
title: {
text: 'GDP and children mortality in South America (2013)'
},
subtitle: {
text: ' '
},
xAxis: {
title: {
enabled: true,
text: 'Mortality rate, per 1,000 live births'
},
startOnTick: true,
endOnTick: true,
showLastLabel: true
},
yAxis: {
labels: {
format: '{value:,.0f}'
},
title: {
text: 'GDP per capita'
}
},
legend: {
enabled: true,
floating: 'true',
align: 'center',
verticalAlign: 'left',
layout: 'horizontal',
borderWidth: 0,
itemDistance: 9,
y: 40
},
credits: {
enabled: false,
text: '',
href: 'https://www.neighborhoodinfodc.org'
},
plotOptions: {
scatter: {
marker: {
enabled: true,
radius: 6,
lineWidth: 2,
symbol: 'circle',
lineColor: null,
states: {
hover: {
enabled: true,
lineColor: 'rgba(100,100,100, 0.5)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
},
tooltip: {
headerFormat: '<span style="color:{series.color}">{series.name}</span><br>',
pointFormat: '{point.x} death children per 1,000 live births <br> GDP per capita: ${point.y}'
}
}
},
series: [{
name: 'Argentina',
color: 'rgba(0, 153, 255, 1)',
data: [[13.3, 15009]]
}, {
name: 'Bolivia',
color: 'rgba(0, 153, 255, 1)',
data: [[39.1, 2868]]
},
{
name: 'Brazil',
color: 'rgba(0, 153, 255, 1)',
data: [[13.7, 11939]]
},
{
name: 'Chile',
color: 'rgba(0, 153, 255, 1)',
data: [[8.2, 15703]]
},
{
name: 'Colombia',
color: 'rgba(0, 153, 255, 1)',
data: [[16.9, 7865]]
},
{
name: 'Ecuador',
color: 'rgba(0, 153, 255, 1)',
data: [[22.5, 6003]]
},
{
name: 'Paraguay',
color: 'rgba(0, 153, 255, 1)',
data: [[21.9, 4248]]
},
{
name: 'Peru',
color: 'rgba(0, 153, 255, 1)',
data: [[16.7, 6662]]
},
{
name: 'Uruguay',
color: 'rgba(0, 153, 255, 1)',
data: [[11.1, 16884]]
},
{
name: 'Venezuela',
color: 'rgba(0, 153, 255, 1)',
data: [[14.9, 12213]]
}
]
});
});
//end chart racial weawlth gap
// Handle the toggle button with class setting:
document.getElementById('gdp-rate').className = 'chart hide';
$('#racegap').click(function () {
var racegap = document.getElementById('total-mortality');
if (racegap.className === 'chart show') {
document.getElementById('total-mortality').className = 'chart hide';
document.getElementById('gdp-rate').className = 'chart show';
document.getElementById('racegap').innerHTML = 'Show yearly total mortality'
} else {
document.getElementById('racegap').innerHTML = 'Show GDP and Rate Mortality'
document.getElementById('gdp-rate').className = 'chart hide';
document.getElementById('total-mortality').className = 'chart show';
}
});
});
</script>
</html>
https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
https://code.highcharts.com/highcharts.js