Skip to content

Instantly share code, notes, and snippets.

@serenaf
Created April 12, 2015 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serenaf/f80ae7a79cf7b41dc1ca to your computer and use it in GitHub Desktop.
Save serenaf/f80ae7a79cf7b41dc1ca to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Adding Tooltips</title>
<script type="text/javascript" src="../d3.v3.js"></script>
<style type="text/css">
body {
background-color: #ddddff;
}
svg {
background-color: white;
}
</style>
</head>
<body>
<h1>WHO Suizide Rate Data </h1>
<script type="text/javascript">
var svg = d3.select("body")
.append("svg")
.attr("width", 300)
.attr("height", 1000);
d3.csv("WHO_mental_health_data.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.suizideRateTotal, +b.suizideRateTotal);
});
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect");
rects.attr("x", 0)
.attr("y", function(d, i) {
return i * 10;
})
.attr("width", function(d) {
return d.suizideRateTotal*10;
})
.attr("height", 8)
.append("title")
.text(function(d) {
return d.country + "'s suizide Rate is " + d.suizideRateTotal;
});
});
</script>
</body>
</html>
country policy plan legislation expenditures psychatrists suizideRateM suizideRat F suizideRateTotal
Afghanistan 1 1 1 * 0.16 6.2 5.3 5.7
Albania 1 1 1 * 1.83 6.6 5.2 5.9
Algeria 1 1 1 7.37 1.55 2.3 1.5 1.9
Angola 0 1 0 * 0.02 20.7 7.3 13.8
Argentina 1 1 0 * * 17.2 4.1 10.3
Armenia 0 0 1 3.38 4.04 5 0.9 2.9
Australia 1 1 1 7.64 12.76 16.1 5.2 10.6
Austria 0 1 1 * 19.71 18.2 5.4 11.5
Azerbaijan 1 1 1 2.5 5.08 2.4 1 1.7
Bahrain 1 1 0 * 8.18 11.6 2.9 8.1
Bangladesh 1 1 0 0.44 0.07 6.8 8.7 7.8
Barbados 1 0 1 * 4.29 4.1 0.6 2.3
Belarus 1 1 1 * 8.77 32.7 6.4 18.3
Belgium 1 1 1 * * 21 7.7 14.2
Belize 1 1 0 * 0.96 4.9 0.5 2.6
Benin 0 0 0 * 0.14 8.8 3.1 5.7
Bhutan 1 1 0 * 0.28 23.1 11.2 17.8
Bolivia (Plurinational State of) 0 1 0 * 1.06 16.2 8.5 12.2
Bosnia and Herzegovina 1 1 1 * 4.95 18 4.1 10.8
Botswana 1 1 1 * 0.25 5.7 2 3.8
Brazil 1 1 1 2.38 3.07 9.4 2.5 5.8
Brunei Darussalam 0 0 1 * 0.98 7.7 5.2 6.4
Bulgaria 1 1 0 1.4 6.75 16.6 5.3 10.8
Burkina Faso 0 0 0 * 0.04 7.3 2.8 4.8
Burundi 0 1 0 0.34 0.01 34.1 12.5 23.1
Côte d'Ivoire 1 1 0 * 0.16 10.6 4.1 7.4
Cabo Verde 0 1 0 * 1.37 9.1 1.6 4.8
Cambodia 1 1 0 * 0.23 12.6 6.5 9.4
Cameroon 0 0 0 0.26 0.03 10.9 3.4 7
Canada 0 1 1 7.2 12.61 14.9 4.8 9.8
Central African Republic 0 0 0 * 0.02 14.1 5.3 9.5
Chad 0 1 0 * 0.01 7.4 2.3 4.7
Chile 0 1 0 2.78 0.99 19 5.8 12.2
China 1 1 0 * 1.53 7.1 8.7 7.8
Comoros 0 1 1 * 0.14 24 10.3 16.9
Congo 0 0 0 * 0.03 14.7 4.6 9.6
Costa Rica 1 1 0 2.91 2.33 11.2 2.2 6.7
Croatia 1 1 1 * 10.25 19.8 4.5 11.6
Cuba 1 1 1 * 10.85 18.5 4.5 11.4
Cyprus 1 1 1 4.82 6.82 7.7 1.5 4.7
Czech Republic 0 1 0 2.91 11.85 21.5 3.9 12.5
Democratic Republic of the Congo 1 1 0 * 0.07 15.8 4.8 10.1
Denmark 1 1 1 * 14.12 13.6 4.1 8.8
Dominican Republic 0 1 1 0.61 1.33 6.1 2.1 4.1
Ecuador 0 1 0 1.2 1 13.2 5.3 9.2
Egypt 1 1 1 2.29 0.54 2.4 1.2 1.7
El Salvador 1 0 0 * 0.16 23.5 5.7 13.6
Eritrea 0 0 0 1.91 0 25.8 8.7 16.3
Estonia 1 0 1 5.78 13.5 24.9 3.8 13.6
Ethiopia 0 0 0 * 0.04 16.5 6.7 11.5
Fiji 0 0 1 1.9 0.23 10.6 4.1 7.3
Finland 1 1 1 3.86 28.06 22.2 7.5 14.8
France 1 1 1 12.91 22.35 19.3 6 12.3
Gabon 0 0 0 0.62 0.27 12.1 4.5 8.2
Gambia 1 1 1 * 0.17 7.6 2.6 5
Georgia 0 0 1 2.83 6.87 5.7 1 3.2
Germany 1 1 1 11 15.23 14.5 4.1 9.2
Ghana 1 1 1 2 0.07 4.2 2.2 3.1
Greece 1 1 1 4.43 12.88 6.3 1.3 3.8
Guatemala 1 1 0 1.46 0.59 13.7 4.3 8.7
Guinea 1 1 0 * 0.03 7.1 2.4 4.7
Guinea-Bissau 0 0 0 * 0 7.2 2.4 4.7
Guyana 1 1 1 1.35 0.53 70.8 22.1 44.2
Haiti 0 0 0 0.61 0.2 3.3 2.4 2.8
Honduras 1 0 0 1.61 0.77 8.3 2.8 5.5
Hungary 0 1 0 5.1 6.52 32.4 7.4 19.1
Iceland 0 1 0 8.69 19.74 21 6.7 14
India 0 1 1 * 0.3 25.8 16.4 21.1
Indonesia 1 1 0 * 0.01 3.7 4.9 4.3
Iran (Islamic Republic of) 1 1 1 3.6 1.49 6.7 3.6 5.2
Iraq 0 1 1 * 0.27 1.2 2.1 1.7
Ireland 1 1 1 * 6.06 16.9 5.2 11
Israel 1 1 1 * 8.24 9.8 2.3 5.9
Italy 1 1 1 5 7.81 7.6 1.9 4.7
Jamaica 1 1 1 6.04 1.1 1.8 0.7 1.2
Japan 1 1 1 4.94 10.1 26.9 10.1 18.5
Jordan 0 0 0 * 1.08 2.2 1.9 2
Kazakhstan 0 0 1 * 6.26 40.6 9.3 23.8
Kenya 0 1 1 * 0.19 24.4 8.4 16.2
Kuwait 1 1 0 * 2.62 1 0.8 0.9
Kyrgyzstan 1 1 1 4 3.51 14.2 4.5 9.2
Lao People's Democratic Republic 1 0 0 * 0.03 11.2 6.6 8.8
Latvia 1 0 1 5.9 10.85 30.7 4.3 16.2
Lebanon 0 0 1 4.8 1.41 1.2 0.6 0.9
Lesotho 0 0 1 1.8 0.05 9.2 3.4 6.1
Liberia 1 1 0 * 0.02 6.8 2 4.3
Lithuania 1 1 1 * 17.76 51 8.4 28.2
Luxembourg 1 1 1 * 21.15 13 4.4 8.7
Madagascar 1 1 1 * 0.05 15.2 6.9 11
Malawi 0 0 1 1 0.01 23.9 8.9 16
Malaysia 1 1 1 0.39 0.83 4.7 1.5 3
Maldives 0 0 0 * 1.59 7.8 4.9 6.4
Mali 0 0 0 * 0.04 7.2 2.7 4.8
Malta 1 1 1 6.71 3.17 11.1 0.7 6
Mauritania 1 1 0 * 0.09 4.5 1.5 2.9
Mauritius 0 1 1 * 1.62 13.2 2.9 8
Mexico 1 1 1 0.65 1.57 7.1 1.7 4.2
Mongolia 1 1 1 2 0.52 16.3 3.7 9.8
Montenegro 1 1 1 * 7.03 24.7 6.4 15.3
Morocco 1 1 1 * 0.9 9.9 1.2 5.3
Mozambique 0 1 0 0.16 0.04 34.2 21.1 27.4
Myanmar 1 1 1 * 0.09 16.5 10.3 13.1
Namibia 1 1 1 * 0.23 4.4 1.4 2.7
Nepal 1 0 0 0.7 0.18 30.1 20 24.9
Netherlands 1 1 1 10.65 18.77 11.7 4.8 8.2
New Zealand 1 1 1 10 9.76 14.4 5 9.6
Nicaragua 0 1 0 1 0.88 15.4 4.9 10
Niger 0 1 0 * 0.03 5.3 1.9 3.5
Nigeria 1 1 1 * 0.06 10.3 2.9 6.5
Norway 1 1 1 * 30.77 13 5.2 9.1
Oman 1 1 0 * 2.31 1.2 0.6 1
Pakistan 1 1 1 * 0.19 9.1 9.6 9.3
Panama 1 1 0 * 3.99 8.1 1.3 4.7
Papua New Guinea 1 1 1 0.1 0.09 15.9 9.1 12.4
Paraguay 1 1 0 0.31 0.84 9.1 3.2 6.1
Peru 1 1 0 0.27 0.57 4.4 2.1 3.2
Philippines 1 1 0 * 0.38 4.8 1.2 2.9
Poland 1 1 1 5.08 5.13 30.5 3.8 16.6
Portugal 1 1 1 5.24 6.14 13.6 3.5 8.2
Qatar 1 1 0 * 1.66 5.7 1.2 4.6
Republic of Korea 1 1 1 * 5.12 41.7 18 28.9
Republic of Moldova 0 1 1 3.24 5.03 24.1 4.8 13.7
Romania 1 1 1 * 6.45 18.4 2.9 10.5
Russian Federation 1 1 1 * 11.61 35.1 6.2 19.5
Rwanda 1 1 0 * 0.05 17.1 7.2 11.9
Saudi Arabia 1 1 1 3.89 2.91 0.6 0.2 0.4
Senegal 1 1 1 * 0.33 8.6 2.8 5.4
Serbia 1 1 0 * 9.61 19.9 5.8 12.4
Sierra Leone 1 1 0 * 0.02 11 4.5 7.7
Singapore 1 1 1 4.14 2.81 9.8 5.3 7.4
Slovakia 1 1 1 * 11.48 18.5 2.5 10.1
Slovenia 0 0 1 8 7.06 20.8 4.4 12.4
Solomon Islands 0 0 1 1.3 0.19 13.9 7.2 10.6
Somalia 0 0 0 * 0.04 18.1 6.8 12.4
South Africa 1 1 1 * 0.27 5.5 1.1 3
Spain 1 1 0 5 8.59 8.2 2.2 5.1
Sri Lanka 1 1 1 * 0.29 46.4 12.8 28.8
Sudan 1 1 0 * 0.06 23 11.5 17.2
Suriname 0 0 1 * 1.14 44.5 11.9 27.8
Swaziland 0 0 1 * 0.17 8.6 4.1 6.2
Sweden 1 1 1 10 3.55 16.2 6.1 11.1
Switzerland 0 1 0 * 41.42 13.6 5.1 9.2
Syrian Arab Republic 1 1 1 2 0.31 0.7 0.2 0.4
Tajikistan 0 0 1 1.22 1.36 5.7 2.8 4.2
Thailand 1 1 1 4 0.44 19.1 4.5 11.4
The former Yugoslav republic of Macedonia 1 0 1 * 9.98 7.3 3.2 5.2
Timor-Leste 0 1 0 * 0.17 10.2 5.8 8
Togo 1 1 0 * 0.03 8.5 2.8 5.5
Trinidad and Tobago 1 1 1 * 0.67 20.4 6.2 13
Tunisia 1 1 1 4.95 1.98 3.4 1.4 2.4
Turkey 1 1 0 * 2.13 11.8 4.2 7.9
Uganda 1 1 * 0.09 26.9 12.3 19.5
Ukraine 1 1 1 * 10.11 30.3 5.3 16.8
United Arab Emirates 0 1 1 * 0.3 3.9 1.7 3.2
United Republic of Tanzania 1 1 1 2.4 0.04 31.6 18.3 24.9
United States of America 1 1 1 * 7.79 19.4 5.2 12.1
Uzbekistan 1 1 1 2.32 3.37 13.2 4.1 8.5
Viet Nam 0 1 0 * 1.01 8 2.4 5
Yemen 0 0 0 * 0.21 4.3 3 3.7
Zambia 1 1 1 * 0.03 20.8 10.8 15.7
Zimbabwe 1 1 1 0.01 0.06 27.2 9.7 18.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment