Skip to content

Instantly share code, notes, and snippets.

@renecnielsen
Created February 24, 2016 16:16
Show Gist options
  • Save renecnielsen/777884b900d913917ec3 to your computer and use it in GitHub Desktop.
Save renecnielsen/777884b900d913917ec3 to your computer and use it in GitHub Desktop.
d3.js Multi-series line chart interactive
date Ageing Aids Animal Welfare Bird Flu BSE Coal Pits EU Countryside Crime Defence Drug Abuse Economy Education Farming German Reunification GM foods Housing Inflation/Prices Inner Cities Local Govt Low Pay Morality NHS Northern Ireland Nuclear Power Nuclear Weapons Pensions Fuel Prices Environment The Pound Poverty/Inequality Privatisation Public Services Immigration Scots/Welsh Assembly Taxation Trade Unions Transport Tsunami Unemployment
19740901 7 1 1 7 1 15 5 4 52 13 9 14 2 6 7 27 1 10 7 3 1 11 1 6 29 1 6 3 28
19741001 4 1 1 9 1 14 9 4 52 14 11 13 3 8 7 19 1 11 4 4 1 14 1 5 26 1 4 3 27
19771101 8 1 6 2 18 4 5 52 12 9 14 3 7 7 21 1 10 4 5 1 11 1 5 22 1 2 2 23
19780801 6 1 6 1 19 5 3 55 11 11 17 3 7 7 15 1 8 5 4 1 13 1 5 22 1 4 2 30
19790201 6 1 6 2 17 6 3 55 14 10 16 4 8 7 20 0 9 5 5 1 13 1 4 19 1 2 4 33
19790401 9 1 5 3 18 6 5 52 10 1 10 17 4 8 6 19 1 9 6 6 2 11 1 5 21 1 2 1 4 32
19800201 6 1 3 1 17 5 5 54 13 1 11 17 5 8 8 20 0 8 7 2 1 12 2 5 20 1 4 5 34
19800401 6 5 1 14 7 4 61 11 8 15 4 5 9 18 0 1 8 4 3 2 10 1 6 23 1 4 5 35
19820901 6 1 0 5 1 18 9 4 59 14 7 14 3 7 8 22 1 10 6 4 2 11 2 4 26 1 5 1 4 34
19821001 4 1 8 1 14 7 3 58 11 7 15 3 6 7 16 7 4 3 2 10 2 4 19 1 3 1 4 37
19821101 7 1 1 6 1 15 6 3 61 13 6 19 3 8 8 16 1 9 8 3 2 9 1 3 20 1 4 1 4 34
19830301 6 1 2 4 1 20 9 6 55 15 8 18 3 7 6 20 1 8 15 3 1 10 2 4 21 1 5 3 40
19830401 4 1 5 1 18 9 4 57 13 6 12 2 5 7 22 1 7 13 3 2 8 1 3 23 2 3 4 36
19830601 4 1 7 1 20 9 4 64 13 6 12 2 6 6 22 1 8 6 2 1 7 4 24 2 2 2 38
19830701 5 9 2 21 7 5 61 13 8 12 3 6 7 17 1 7 6 3 1 10 1 3 20 1 3 1 3 33
19830801 4 1 7 2 19 8 5 66 15 7 15 2 6 7 17 1 10 8 4 2 10 1 5 22 1 4 1 3 33
19830901 5 1 8 2 23 9 6 62 15 6 15 2 4 7 16 1 8 9 4 2 8 3 23 4 2 32
19831001 3 1 4 1 24 10 5 68 16 6 12 3 4 5 21 1 1 7 5 3 2 9 1 5 24 1 3 1 2 30
19840101 5 1 3 1 29 13 7 59 16 9 13 2 7 11 17 0 1 8 6 4 1 9 1 6 21 1 4 2 30
19840201 5 1 4 1 31 11 5 61 16 6 15 3 3 6 17 9 5 3 2 8 1 4 23 3 2 26
19840301 8 1 1 4 1 17 13 3 57 15 5 15 1 5 6 19 1 10 7 5 1 8 1 5 27 4 1 1 29
19840401 6 3 1 22 15 4 51 14 8 14 3 6 6 26 1 8 7 5 2 7 1 5 31 1 4 2 28
19840601 3 1 3 2 17 18 3 55 20 8 11 2 4 6 26 2 7 11 3 2 6 1 6 26 1 4 3 27
19840801 4 1 2 2 22 22 4 62 14 5 16 3 5 5 20 0 2 9 9 4 1 7 1 6 17 6 3 24
19840901 4 1 4 1 18 16 4 54 17 6 18 4 5 6 19 1 6 15 4 2 8 2 5 26 1 7 1 3 25
19841001 1 1 3 1 23 12 5 60 16 6 16 3 5 5 19 1 6 8 5 3 6 2 6 25 6 2 28
19841101 2 4 22 14 6 60 21 0 6 14 4 5 7 19 1 2 7 8 7 2 8 1 6 26 1 7 1 2 27
19841201 3 1 18 15 5 61 21 7 12 4 6 6 18 1 9 4 4 2 9 1 6 25 1 4 1 2 27
19850101 1 1 4 1 23 17 4 54 15 1 8 11 3 5 6 18 0 1 11 2 5 2 7 6 27 6 1 28
19850201 1 2 1 23 16 6 59 18 1 5 11 4 5 7 21 1 1 10 3 6 2 8 1 6 27 5 2 29
19850301 1 2 1 24 12 5 57 18 7 13 3 5 6 19 1 9 4 4 8 1 5 31 5 1 26
19850401 1 1 1 19 17 5 61 18 6 12 4 4 6 18 1 10 3 6 2 7 1 5 30 4 1 2 24
19850501 2 1 24 15 7 63 17 6 10 3 5 6 16 1 7 3 5 1 9 3 28 4 1 26
19850601 1 1 2 1 26 12 7 65 16 6 8 3 5 4 19 1 5 4 5 2 6 1 3 29 1 5 0 2 21
19850701 1 1 6 1 20 11 5 71 23 5 9 4 5 6 22 2 10 6 5 3 6 1 5 38 1 7 3 22
19850801 3 1 25 11 7 55 21 5 11 4 4 8 24 1 7 7 5 2 6 4 29 6 3 24
19850901 4 1 25 14 8 55 19 5 8 4 5 8 20 1 7 4 6 2 7 1 4 33 0 5 3 21
19851001 2 1 25 19 4 48 14 5 8 3 5 9 17 0 1 5 2 7 1 8 4 29 1 4 0 2 20
19851101 0 1 3 1 24 25 3 49 12 5 9 2 3 11 20 1 5 2 8 1 7 1 4 33 3 2 27
19851201 1 3 26 15 4 52 14 0 5 10 3 4 9 16 1 6 2 9 1 6 2 24 2 1 22
19860101 4 2 32 17 7 54 12 5 9 2 1 10 16 0 3 1 5 1 6 3 25 2 1 30
19860201 6 2 24 20 4 55 11 0 7 8 2 4 6 24 0 4 4 8 1 6 2 27 1 3 0 1 25
19860301 1 4 1 28 10 10 54 12 1 8 12 6 3 11 16 2 5 4 9 1 7 1 5 25 1 4 0 2 28
19860401 1 1 5 30 7 5 59 12 8 10 4 3 14 13 1 3 1 8 2 6 4 30 1 3 2 20
19860501 1 1 1 28 9 5 65 13 6 13 2 3 8 15 0 1 4 2 8 1 8 3 29 3 1 23
19860601 1 32 10 4 67 11 0 8 12 3 2 9 12 0 1 3 1 7 2 5 1 3 25 1 2 0 2 23
19860701 1 1 34 11 5 70 10 6 13 2 2 7 14 0 1 3 2 6 3 5 1 3 21 2 2 24
19860801 1 0 1 1 35 13 6 66 10 0 7 17 2 3 7 12 0 1 4 2 6 3 8 1 22 2 2 15
19860901 0 2 38 13 5 62 9 0 8 18 2 3 8 13 1 4 3 7 2 6 2 22 3 2 15
19861001 1 1 33 10 6 58 12 7 21 2 4 7 18 0 4 4 6 2 8 1 3 27 3 0 2 14
19861101 1 1 40 12 7 55 12 9 22 3 4 7 17 0 1 5 8 8 1 7 1 3 27 1 6 1 11
19861201 1 1 1 3 1 47 15 7 41 12 0 13 26 3 4 9 15 1 4 10 7 6 2 25 1 5 2 7
19870101 1 1 3 2 39 15 6 42 13 11 23 2 3 6 16 1 4 15 7 1 8 2 26 7 2 9
19870201 1 1 4 2 38 20 6 32 16 1 12 22 2 4 6 19 1 7 16 9 1 7 1 3 30 9 2 6
19870301 1 1 2 1 41 13 6 34 13 15 21 2 5 7 19 1 7 9 8 1 8 1 4 37 1 9 2 6
19870401 1 1 4 1 35 20 8 33 14 13 11 3 4 7 23 1 6 6 7 1 7 1 3 42 1 11 2 6
19870701 3 1 40 17 7 23 17 10 11 4 4 9 24 2 6 6 10 1 7 1 4 44 1 11 0 3 6
19870801 1 1 3 1 50 16 8 18 17 12 9 3 4 10 25 1 6 4 7 1 5 3 44 8 3 6
19870901 1 1 1 2 1 47 20 7 20 18 9 8 3 4 8 33 1 5 5 8 1 5 1 3 40 1 7 4 0 9
19871001 2 2 1 4 2 37 21 6 13 21 1 15 6 2 4 8 33 2 6 6 10 1 6 1 4 46 7 1 4 7
19871101 2 2 1 6 1 38 20 9 11 19 12 5 2 3 7 40 1 6 2 6 5 3 41 8 3 0 6
19871201 1 1 1 4 1 41 22 7 10 17 1 11 4 2 4 7 36 1 6 7 0 3 1 3 43 8 0 2 8
19880101 1 1 1 3 55 25 8 9 19 1 1 9 3 2 2 9 26 2 5 1 8 - 6 4 35 1 6 0 3 0 7
19880201 3 1 35 39 7 7 22 0 16 3 2 3 8 30 2 6 1 9 5 1 3 40 1 7 3 7
19880301 1 1 1 4 2 35 27 6 10 22 10 3 3 2 7 37 2 8 1 13 6 1 3 40 1 6 3 8
19880401 3 1 36 27 7 9 23 11 3 3 3 6 37 2 7 1 10 5 1 3 38 1 6 3 0 7
19880501 1 1 2 1 40 27 9 10 19 10 5 3 2 8 36 1 8 1 12 5 1 4 36 9 1 4 8
19880601 1 1 7 2 37 36 11 14 22 1 8 7 4 3 6 27 3 8 2 19 1 4 3 25 7 2 6
19880701 1 1 3 1 33 35 5 9 21 7 4 1 2 6 32 2 10 2 13 5 1 3 38 1 9 3 1 6
19880801 1 1 3 1 32 40 6 9 18 6 4 3 2 6 31 1 7 2 11 5 1 3 38 8 2 1 6
19880901 3 2 30 37 5 8 20 1 1 5 2 2 2 5 38 3 7 1 8 5 1 2 40 0 7 0 3 6
19881001 1 1 1 3 1 26 38 6 8 19 1 8 3 3 2 4 32 2 7 3 10 1 4 2 45 7 2 5
19881101 0 0 3 1 37 36 4 9 20 6 3 2 1 5 35 2 10 6 10 7 3 38 1 7 2 6
19881201 3 2 41 25 5 8 19 1 7 2 2 2 6 35 2 10 3 10 1 5 1 2 35 1 6 3 6
19890101 3 1 36 27 5 10 25 5 3 2 2 5 38 0 1 20 4 12 5 2 41 5 0 2 6
19890201 2 3 2 30 23 3 9 28 6 2 2 2 5 47 0 1 12 5 11 5 3 35 7 3 7
19890301 1 3 2 26 29 5 9 28 0 6 2 3 2 6 37 2 13 2 9 8 3 30 8 3 0 5
19890401 3 1 28 34 6 11 25 6 2 3 2 5 33 2 13 3 8 6 30 1 7 3 9
19890501 4 2 36 26 7 10 28 6 2 3 2 7 30 2 11 4 9 7 1 2 28 7 3 7
19890601 3 1 34 41 7 13 27 1 4 2 3 1 5 29 1 14 1 6 4 1 2 25 9 3 7
19890701 1 1 5 1 31 31 6 10 26 6 2 4 1 5 34 1 12 3 6 6 3 30 0 7 0 4 1 6
19890801 5 1 25 46 5 11 21 5 3 3 2 7 28 2 10 5 6 6 2 32 8 0 4 7
19890901 4 1 24 56 4 13 19 6 2 2 1 4 28 1 8 4 4 7 1 35 4 3 7
19891001 0 0 7 1 25 58 3 10 20 5 1 2 2 5 29 1 8 2 7 7 2 32 6 0 5 1 8
19891101 19 1 30 16 4 11 24 6 2 2 1 4 36 0 1 11 1 7 7 2 33 8 5 1 8
19891201 9 1 40 14 7 11 26 8 2 3 1 10 36 1 14 2 6 5 3 27 8 4 7
19900101 0 5 2 29 24 6 12 30 1 1 9 2 3 2 6 44 1 13 2 4 8 3 33 6 4 8
19900201 8 1 29 25 5 10 26 7 2 3 2 6 38 1 14 1 6 7 1 3 40 7 4 8
19900301 0 7 2 26 34 5 10 24 1 8 2 3 2 6 34 2 11 1 5 1 8 1 3 26 8 0 4 3 7
19900401 6 1 30 40 5 10 25 6 2 2 2 6 33 2 13 2 4 7 1 4 25 9 7 6
19900501 1 1 9 1 27 47 6 10 22 1 5 2 1 2 5 32 2 12 2 5 1 6 1 3 24 6 0 6 6
19900601 0 0 7 2 28 47 7 11 26 0 7 3 2 1 4 36 2 20 1 3 1 5 3 25 9 0 4 7
19900701 8 1 27 36 6 10 29 1 7 3 3 2 5 34 1 15 2 4 1 4 4 26 8 5 8
19900801 9 28 38 6 10 23 0 1 6 4 4 1 4 34 2 8 3 4 3 1 2 30 8 6 7
19900901 11 1 28 34 4 10 27 1 7 2 3 2 4 40 0 2 12 2 2 1 5 1 5 31 9 8 7
19901001 0 16 1 20 35 5 7 28 1 7 2 1 1 4 44 0 1 10 3 3 1 4 0 3 28 5 7 6
19901101 17 1 21 47 6 9 25 1 8 3 3 2 4 34 3 9 3 4 5 3 30 8 7 7
19901201 1 1 0 9 1 19 47 3 9 29 8 2 2 2 4 34 4 10 1 2 6 3 36 7 5 7
19910101 0 5 1 22 41 6 11 27 2 6 3 4 2 7 35 2 12 4 6 1 5 31 1 10 7 8
19910201 7 1 26 28 6 9 33 1 5 2 4 2 5 37 0 3 13 1 3 1 5 1 3 35 1 10 0 6 8
19910301 9 2 23 26 4 10 32 1 6 2 4 2 4 36 3 13 1 4 5 1 4 29 1 11 9 8
19910401 1 1 12 1 22 26 5 12 33 5 2 4 2 4 41 4 11 1 4 6 1 29 1 10 8 7
19910501 1 1 7 1 29 40 4 11 27 5 2 3 2 6 46 3 10 1 2 1 5 1 26 7 1 7 8
19910601 1 1 12 1 25 21 6 10 26 1 5 2 2 2 4 40 1 2 11 1 2 5 1 34 8 8 7
19910701 1 1 13 1 24 37 6 14 28 1 7 2 2 3 5 40 4 12 1 2 5 29 6 1 7 9
19910801 9 1 24 20 6 12 33 7 3 3 3 5 45 4 10 1 2 1 6 1 35 6 10 10
19910901 1 1 1 11 1 26 24 4 9 33 1 6 2 1 2 6 43 4 11 1 4 1 6 1 29 1 4 1 9 10
19911001 26 1 22 21 6 10 27 0 1 6 3 3 1 5 41 2 9 1 3 1 6 29 6 9 7
19911101 22 1 25 24 5 13 30 5 2 2 3 3 39 1 3 10 1 2 1 6 33 6 5 8
19911201 7 2 19 26 5 15 32 1 5 2 2 2 3 49 3 9 1 3 7 1 27 7 6 10
19920101 5 1 18 64 2 13 27 5 3 2 2 3 42 9 9 1 2 5 26 7 2 9 8
19920201 4 1 20 69 5 10 27 6 2 1 4 4 44 11 11 2 2 1 5 1 27 5 1 11 9
19920401 5 1 21 64 6 12 27 1 4 3 2 3 4 35 9 6 1 1 0 5 1 34 3 2 6 6
19920501 1 1 8 1 23 35 6 12 29 6 4 1 5 4 38 7 13 1 2 1 7 1 23 0 5 4 12 9
19920601 1 1 8 1 30 40 6 10 29 6 3 2 5 5 42 10 12 3 1 6 1 18 0 3 11 8 9
19920701 1 1 8 1 28 35 7 7 32 1 6 4 2 4 3 45 3 8 9 1 2 1 6 1 18 4 2 11 10
19920801 1 1 1 8 3 28 34 7 10 34 1 1 6 2 1 2 5 41 1 9 9 1 2 1 9 1 21 4 1 8
19920901 1 11 2 31 10 9 12 37 0 8 3 1 3 4 55 2 11 1 2 1 4 1 22 1 3 1 10
19921001 14 1 31 13 10 9 29 1 7 2 1 2 4 54 1 2 11 1 4 1 5 32 1 4 17 10
19921101 14 3 34 13 13 8 32 1 1 7 1 1 2 5 50 3 9 1 3 2 4 39 3 16 6
19921201 10 1 29 19 6 8 28 1 5 1 2 3 6 66 1 2 9 2 4 1 6 1 13 5 12 8
19930101 1 1 11 1 37 18 7 8 30 1 4 2 1 2 4 58 1 3 10 1 3 1 7 1 15 2 14 8
19930201 1 13 1 28 11 5 7 28 1 4 2 2 1 4 72 1 10 1 3 1 5 18 6 18 10
19930301 13 1 23 13 5 12 32 2 3 2 2 2 4 66 2 2 6 2 2 2 6 2 16 3 22 9
19930401 1 19 2 19 40 4 15 29 2 5 1 2 2 3 49 2 2 8 2 2 4 12 2 0 10 14
19930501 1 7 1 14 57 3 12 31 3 4 2 2 3 4 49 2 3 7 2 1 5 1 17 2 8 12
19930601 1 9 1 15 60 4 15 30 3 4 2 1 2 2 43 1 4 7 2 3 1 4 1 27 3 5 11
19930701 2 22 2 22 2 4 13 35 7 6 2 2 3 4 54 1 8 3 4 1 5 1 23 5 9 13
19930801 1 20 3 32 2 5 12 34 4 6 2 2 2 4 52 1 10 3 8 1 6 17 5 11 11
19930901 1 24 2 29 2 9 10 44 7 6 2 1 2 4 58 1 11 4 6 2 6 14 4 11 10
19931001 4 14 3 19 3 6 10 32 41 5 1 1 2 3 41 8 7 5 6 16 4 4 12
19931101 5 17 3 16 1 5 9 29 49 4 2 1 2 2 37 8 4 4 1 5 10 5 6 10
19931201 1 23 1 25 5 5 11 37 7 2 1 3 3 48 1 11 8 5 1 6 18 7 9 12
19940101 1 21 2 30 3 6 11 32 6 3 2 3 4 50 8 8 6 2 6 11 6 9 12
19940201 1 26 2 26 3 7 10 29 1 7 2 2 2 5 45 9 11 9 2 5 8 7 14 7
19940301 3 27 2 13 6 5 12 27 2 6 3 2 4 4 46 14 17 14 1 6 6 9 9 10
19940401 1 24 1 19 4 7 9 25 5 4 2 2 5 44 1 19 22 4 1 8 10 9 12 10
19940501 1 21 2 13 2 3 10 30 1 5 4 2 2 3 46 1 23 31 5 1 7 6 13 7 10
19940601 1 24 1 26 2 6 11 32 1 5 4 1 3 5 49 1 15 4 1 6 11 6 8 16
19940701 1 19 1 34 2 6 12 34 1 7 5 2 3 5 51 1 14 5 2 8 11 11 13 17
19940801 0 0 24 1 23 3 8 9 32 1 7 4 1 4 4 55 1 12 4 2 8 17 7 0 4 17
19940901 1 1 1 19 2 34 4 10 11 30 3 9 3 2 2 6 45 2 1 15 5 1 9 1 16 1 4 6 23
19941001 0 0 17 2 16 3 7 11 35 2 10 2 2 5 53 2 1 14 5 1 9 19 1 6 0 6 21
19941101 20 1 20 2 10 7 37 2 9 3 1 4 5 57 2 1 12 6 1 9 13 5 4 18
19941201 1 25 2 18 3 6 11 32 1 6 4 2 4 4 54 6 1 13 3 2 7 12 5 5 19
19950101 0 0 22 1 24 4 8 11 32 1 9 3 1 4 5 70 2 2 12 5 1 8 7 5 7 20
19950201 2 2 5 32 2 15 4 6 10 33 1 8 3 1 4 5 41 2 1 13 6 1 10 1 4 1 5 0 14 18
19950301 1 1 4 23 2 24 5 8 13 29 1 11 4 2 5 5 40 4 1 14 8 1 10 5 4 12 21
19950401 4 34 3 16 5 7 9 31 1 9 5 1 2 3 41 2 1 12 7 2 11 8 3 10 17
19950501 1 23 3 21 5 12 11 31 2 8 4 1 3 6 39 3 1 14 7 1 14 7 1 2 5 22
19950601 1 25 2 19 5 5 13 30 3 8 6 1 3 4 41 2 1 11 6 1 9 1 10 5 0 7 24
19950701 1 30 1 16 7 6 13 30 1 8 4 1 2 3 39 10 1 7 8 1 7 7 1 4 11 21
19950801 1 37 1 18 16 7 16 29 9 4 1 3 6 35 2 2 10 5 1 8 1 7 2 3 4 19
19950901 1 1 26 1 18 28 6 15 27 9 3 1 3 5 33 3 11 6 1 8 6 1 3 1 3 23
19951001 15 1 20 28 9 13 31 6 5 1 4 3 34 2 4 7 4 1 9 8 2 5 3 27
19951101 1 32 1 16 4 5 15 29 7 4 2 3 5 37 3 1 10 5 1 10 5 1 5 3 25
19951201 1 1 3 30 2 19 8 6 13 29 7 4 1 4 4 39 3 2 11 5 1 9 7 1 3 2 26
19960101 1 27 2 17 7 5 19 32 7 4 2 4 5 49 1 2 10 6 1 5 1 4 1 3 2 26
19960201 1 32 1 17 5 6 18 26 8 6 1 3 5 34 2 1 10 3 8 7 1 3 4 30
19960301 2 26 2 17 8 6 21 32 7 5 2 4 4 37 1 2 11 5 2 7 6 5 3 35
19960401 1 23 2 20 4 8 30 33 8 8 2 5 38 2 1 12 5 3 10 4 1 2 43
19960501 1 20 1 17 3 5 27 31 9 6 1 4 40 1 1 9 4 3 7 6 2 4 44
19960601 13 1 21 7 8 26 33 7 4 1 4 41 11 2 12 7 1 7 4 4 4 36
19960701 1 22 1 19 3 7 17 40 8 4 1 5 45 5 1 13 8 2 9 3 3 8 28
19960801 1 33 1 21 5 8 13 33 8 5 2 6 44 5 2 10 8 2 9 3 3 5 33
19960901 1 22 1 20 4 5 13 39 7 5 2 3 49 11 1 12 6 1 7 3 3 4 30
19961001 1 23 21 5 9 14 39 6 3 1 6 35 10 13 8 1 9 6 3 3 31
19961101 2 22 13 4 5 19 42 6 3 2 4 47 3 17 7 2 7 3 1 4 4 34
19961201 2 16 14 26 3 14 37 7 3 1 3 50 5 19 6 1 8 3 3 3 31
19970101 3 23 19 4 5 14 37 10 3 2 5 42 8 23 7 9 4 1 3 3 32
19970201 1 1 7 28 1 16 2 5 14 31 8 3 1 4 42 3 1 20 9 8 4 1 2 2 31
19970301 1 1 1 31 1 22 4 5 16 36 8 4 1 4 47 1 1 13 7 1 4 1 3 34
19970401 1 1 1 35 26 2 6 14 36 8 4 1 4 47 2 1 12 7 1 1 8 1 2 3 32
19970601 1 1 21 1 28 2 7 17 45 7 4 1 6 45 2 1 12 7 4 2 2 4 35
19970701 1 16 1 27 2 9 18 39 9 5 1 5 47 2 1 13 11 1 5 1 2 7 35
19970801 1 1 1 23 1 23 2 6 19 49 8 4 1 6 46 4 1 13 7 1 4 2 2 4 34
19970901 1 1 1 30 24 2 6 14 45 8 2 1 5 51 4 1 11 10 1 1 3 3 39
19971001 2 43 27 2 3 22 54 7 3 2 5 63 3 17 2 1 3 4 28
19971101 1 1 2 33 28 1 3 18 43 6 4 2 5 49 1 15 6 2 3 3 39
19971201 1 1 2 35 27 2 5 18 45 10 4 1 8 48 2 1 13 5 1 2 3 5 1 38
19980101 1 1 2 29 22 2 4 19 43 9 3 2 5 49 2 1 12 5 1 2 2 4 36
19980201 2 38 37 2 6 24 38 10 4 2 7 42 2 14 4 2 3 4 35
19980301 2 23 37 3 7 19 42 8 5 2 9 43 1 13 3 2 3 3 41
19980401 3 20 41 2 6 13 39 7 2 1 7 36 1 11 4 2 3 4 37
19980501 1 1 8 23 27 3 6 14 32 9 3 1 4 35 2 1 11 5 2 3 4 43
19980601 3 20 30 2 5 15 27 8 2 2 5 33 2 10 7 3 4 3 44
19980701 1 1 5 25 29 2 6 14 31 8 3 1 4 35 4 9 5 1 3 3 3 43
19980801 1 1 15 28 22 1 4 13 28 8 3 1 4 33 4 1 8 3 2 3 2 44
19980901 1 1 18 29 29 2 5 16 30 9 2 1 4 39 1 9 4 2 3 3 42
19981001 1 1 20 24 2 5 17 33 9 3 1 4 34 2 1 8 4 3 4 4 1 46
19981101 1 1 0 16 24 3 5 16 31 9 3 1 3 36 5 8 5 1 3 3 3 44
19981201 1 1 11 24 2 6 18 30 10 3 1 4 39 12 10 7 1 4 3 4 48
19990101 1 1 1 14 27 3 7 20 29 10 3 1 3 41 1 8 4 1 3 4 3 49
19990201 10 23 2 6 19 32 9 4 4 40 2 10 4 3 4 5 51
19990301 1 1 11 25 3 10 19 31 10 4 1 5 39 1 1 1 11 5 3 5 5 52
19990401 17 22 2 5 18 29 12 4 2 45 10 4 4 4 5 51
19990501 1 1 13 24 3 4 20 30 11 3 1 4 44 1 9 5 3 3 5 48
19990601 1 1 12 24 3 4 20 29 10 5 2 5 39 1 1 8 6 5 4 4 52
19990701 1 1 12 23 6 3 20 28 12 5 2 3 39 1 1 9 5 1 2 3 6 1 51
19990801 1 1 26 22 4 3 17 29 11 5 1 3 38 1 1 1 9 5 1 2 4 4 47
19990901 1 1 15 25 2 4 19 29 8 5 1 4 44 1 9 4 3 4 5 53
19991001 1 1 12 25 2 3 21 33 10 6 1 3 41 1 9 3 1 2 4 5 51
19991101 1 1 16 24 2 4 20 25 10 5 1 3 43 2 1 8 4 2 4 4 51
19991201 1 1 25 26 2 4 20 26 10 4 2 5 36 2 9 4 3 5 4 52
20000101 1 1 1 22 23 3 3 22 22 11 6 1 3 38 1 10 5 4 2 5 52
20000201 17 22 2 3 22 18 11 6 1 3 34 1 12 4 5 2 9 55
20000301 14 25 2 4 17 20 10 4 1 4 40 2 11 4 3 2 4 58
20000401 1 1 11 37 3 7 19 22 10 4 1 4 34 3 9 5 2 4 4 62
20000501 1 1 7 33 3 3 20 21 8 5 1 6 34 2 9 4 1 2 5 5 1 59
20000601 1 1 9 33 5 4 19 23 11 5 1 4 36 2 1 1 7 6 3 3 5 2 62
20000701 12 23 7 4 18 20 10 5 1 4 35 2 7 7 4 2 5 65
20000801 1 1 13 30 2 4 22 21 11 5 1 4 29 1 9 4 3 2 0 11 1 66
20000901 1 1 12 32 3 3 24 21 9 6 2 4 35 1 1 10 4 5 4 8 60
20001001 1 1 1 7 33 7 4 24 24 11 5 2 4 38 1 9 6 2 4 9 60
20001101 1 1 1 12 34 5 4 21 25 11 5 2 5 35 2 1 9 4 3 4 11 59
20001201 1 1 4 26 9 5 23 22 10 6 1 5 40 1 1 9 3 2 4 7 61
20010101 1 1 5 31 6 4 30 22 14 5 2 6 32 2 9 5 2 4 6 61
20010201 1 1 1 6 23 4 2 28 19 10 5 2 34 2 1 15 4 1 2 3 4 1 66
20010301 1 1 1 6 28 4 3 30 23 1 9 5 2 35 3 1 13 4 2 4 4 61
20010401 0 0 2 6 33 6 2 30 17 9 7 3 32 1 1 13 3 1 7 61
20010601 1 1 7 29 4 2 32 19 1 9 6 2 32 1 1 11 3 1 2 8 4 61
20010701 1 1 1 10 25 6 2 32 21 1 8 5 1 36 1 9 5 3 3 63
20010801 2 2 0 19 24 4 3 31 18 1 8 5 1 32 1 1 11 7 2 3 66
20010901 1 1 1 9 20 6 2 36 21 9 6 2 37 1 10 4 1 2 4 2 69
20011001 1 1 1 13 24 5 2 30 19 8 6 2 41 1 12 3 1 4 3 2 68
20011101 1 1 1 9 26 8 2 36 19 1 10 6 2 24 2 1 10 5 2 3 1 1 73
20020101 1 1 2 10 34 3 2 33 18 1 10 8 3 24 3 1 9 4 1 1 2 2 78
20020201 1 1 1 10 33 3 2 31 20 1 9 4 2 30 7 5 1 2 2 1 1 81
20020301 2 2 3 8 17 9 2 37 16 1 10 5 3 28 1 7 4 1 3 2 1 79
20020401 2 2 24 12 3 2 41 15 1 17 7 2 24 7 3 1 2 3 0 1 72
20020501 2 2 19 12 2 47 16 1 15 8 5 27 1 7 5 3 2 4 1 1 71
20020601 1 1 19 9 2 1 50 14 1 10 9 3 27 7 4 2 2 2 0 8 74
20020701 1 1 22 11 3 1 53 17 1 13 9 3 21 1 6 7 4 1 3 1 61
20020901 2 2 10 14 7 2 44 18 2 15 13 7 26 1 2 7 8 4 2 6 1 1 64
20021001 10 17 3 35 20 12 7 5 28 1 7 14 61
20021101 1 1 17 16 3 2 26 21 1 11 9 5 30 1 2 9 15 1 1 4 1 57
20021201 2 2 14 15 4 2 27 23 1 11 9 7 32 1 1 8 13 2 5 1 57
20030101 10 11 3 32 27 9 8 7 41 1 1 8 10 53
20030201 9 13 4 40 27 11 10 9 49 2 1 10 7 56
20030301 12 11 6 37 24 12 11 8 43 2 3 9 5 54
20030401 24 15 6 31 17 17 10 9 34 1 2 8 4 41
20030501 32 12 4 28 24 9 9 10 42 1 2 10 7 48
20030601 9 15 8 24 21 9 11 8 51 1 2 10 10 54
20030701 8 23 6 26 26 9 12 9 45 1 9 7 54
20030801 6 13 9 34 19 13 17 11 34 2 8 8 54
20030901 8 13 6 34 17 9 14 11 33 2 7 18 53
20031001 18 9 4 28 20 11 18 13 40 1 7 8 52
20031101 5 14 4 28 25 7 16 13 51 1 7 9 45
20031201 4 15 10 27 20 10 21 27 29 1 1 10 10 48
20040101 1 1 5 7 6 1 32 18 8 22 38 24 9 9 1 1 1 3 38
20040201 1 1 3 7 51 1 33 17 8 19 35 23 2 8 5 1 1 1 2 37
20040301 1 1 4 5 65 1 28 17 10 19 28 27 1 3 10 5 1 1 2 1 34
20040401 2 2 14 9 29 2 23 14 1 10 17 29 24 1 2 10 6 1 2 2 2 22
20040501 1 1 18 8 33 1 23 21 2 10 19 36 28 1 1 2 10 9 1 1 1 0 2 22
20040601 1 1 5 12 25 1 25 32 1 6 23 23 31 1 1 2 10 12 2 1 2 2 26
20040701 1 1 3 9 35 2 26 20 1 9 30 22 29 1 1 2 11 14 1 2 3 2 24
20040801 1 1 3 10 31 2 25 17 1 10 32 24 28 1 1 3 10 18 1 2 3 2 1 26
20040901 15 12 4 21 18 8 19 30 30 1 4 11 30 20
20041001 10 12 5 23 17 10 19 30 22 2 4 7 20 19
20041101 8 14 3 25 15 8 29 39 23 2 4 10 22 26
20041201 7 12 4 24 15 9 23 46 25 1 5 11 19 20
20050101 6 9 3 24 12 8 26 49 25 2 3 9 21 18
20050201 6 12 4 26 14 11 29 32 27 1 5 10 18 20
20050301 3 3 9 14 3 3 24 13 10 24 22 31 2 1 5 12 19 1 3 8 2 4 26
20050501 9 10 7 24 14 14 17 17 34 2 5 12 17 24
20050601 10 13 7 28 12 14 24 12 36 2 6 12 18 24
20050701 3 16 5 31 14 10 25 13 35 2 7 12 21 23
20050801 5 18 5 17 13 7 16 11 31 5 9 12 28 25
20050901 7 18 4 17 13 8 15 11 34 4 9 11 30 27
20051001 11 15 3 16 15 8 17 13 29 1 8 11 35 24
20051101 16 13 5 19 12 23 10 29 1 12 23 30
20060101 11 19 6 16 12 7 17 10 34 1 16 13 17 31
20060201 4 24 5 16 14 8 21 10 35 2 11 14 14 32
20060301 3 20 6 15 14 10 21 40 3 9 9 22 33
20060401 4 20 6 14 14 10 19 38 3 11 13 14 35
20060501 5 26 5 18 11 10 17 34 3 11 13 9 38
20060601 3 3 4 19 7 3 21 13 14 15 6 31 2 3 11 15 5 1 3 2 1 0 41
20060701 2 2 4 21 7 4 21 15 8 14 5 39 3 5 13 20 11 2 8 3 2 36
20060801 4 4 6 25 6 5 14 15 9 9 5 38 3 6 13 16 10 1 3 3 2 2 42
20061001 8 24 5 16 14 9 11 36 7 13 15 2 44
20061101 4 29 7 15 15 10 11 34 15 12 13 1 48
20061201 3 3 5 28 7 4 13 16 11 9 1 7 41 3 4 15 13 2 4 5 3 2 48
20070101 3 3 4 34 7 6 8 14 10 7 2 8 35 3 4 17 12 1 2 5 3 2 49
20070401 4 4 2 23 6 5 8 15 8 5 1 9 44 3 4 13 13 1 2 5 2 1 53
20070501 5 5 3 20 6 4 8 15 8 6 2 13 50 4 4 13 17 1 2 7 3 2 53
20070601 6 6 2 27 5 4 7 14 9 5 2 2 60 15 4 12 11 1 2 4 4 2 56
20070701 4 17 5 7 13 5 3 1 59 2 12 7 3 49
20070801 5 5 1 15 7 3 6 14 6 2 1 1 64 1 4 13 6 1 1 3 1 1 45
20070901 1 16 9 6 18 9 5 52 2 20 8 1 57
20071001 1 20 8 10 19 9 5 32 3 15 7 1 58
20071201 1 19 10 13 15 8 5 22 1 18 8 1 60
20080101 2 20 9 9 16 9 4 21 1 19 6 1 63
20080201 6 6 2 27 10 5 9 16 8 6 2 19 1 6 17 6 2 4 2 2 65
20080301 1 17 13 8 24 7 4 28 1 16 7 1 68
20080401 1 19 9 5 17 7 3 19 1 21 8 1 75
20080501 1 17 9 6 14 7 5 20 20 9 1 76
20080601 2 18 9 7 12 7 8 19 1 16 8 1 77
20080701 2 17 10 7 11 6 3 17 19 10 2 75
20080801 2 13 19 13 8 8 17 1 26 9 1 78
20080901 2 16 7 11 5 6 18 1 22 6 1 73
20081001 1 14 8 12 7 9 18 1 26 5 1 77
20081101 1 17 7 11 6 7 19 2 22 4 1 78
20081201 1 17 7 12 7 15 2 17 1 80
20090101 2 14 7 12 7 6 16 2 17 4 1 78
20090201 2 15 9 15 5 9 19 2 26 5 2 83
20090401 1 13 7 16 8 8 18 1 29 5 1 84
20090501 3 17 20 12 6 8 14 3 15 4 1 79
20090601 3 17 4 12 12 11 14 3 15 6 3 86
20090701 2 13 4 15 9 11 15 2 14 5 5 82
20090801 2 17 7 12 6 9 15 3 21 6 3 84
20091001 2 21 5 8 10 10 2 21 3 82
20091101 2 25 4 9 6 11 13 2 15 6 9 3 82
20100201 1 29 6 10 5 12 12 1 15 6 17 3 85
20100301 2 19 7 10 6 10 13 1 18 6 12 3 83
20100401 2 16 6 10 7 15 16 2 18 6 5 4 83
20100501 3 17 7 11 15 15 2 15 5 80
20100601 4 20 7 11 5 20 16 1 15 11 6 5 78
20100701 3 15 7 12 4 17 16 2 17 6 4 5 85
20100801 3 12 6 11 5 17 18 1 19 6 4 9 85
20100901 2 13 5 10 5 22 16 2 21 10 2 7 85
20101001 3 8 9 10 7 28 13 2 20 8 2 26 79
20101101 4 10 7 8 3 15 9 2 24 7 2 26 82
20101201 4 12 7 10 14 9 3 22 36 79
20110101 4 11 6 8 3 18 9 4 20 6 3 40 73
20110201 5 12 7 6 3 18 8 7 22 7 2 41 75
20110301 5 10 7 7 3 21 10 2 22 5 3 39 70
20110401 8 12 9 7 4 19 11 6 25 5 5 35 71
20110501 15 10 8 9 4 17 10 2 29 7 4 29 73
20110601 8 12 11 8 5 16 12 3 30 5 6 15 76
20110701 11 11 11 9 5 21 14 3 29 7 4 10 81
20110801 8 9 13 10 4 18 15 3 39 7 3 4 80
20110901 9 9 13 8 5 19 14 6 41 7 3 6 79
20111001 5 10 14 8 5 22 26 3 30 7 4 4 78
20111101 4 16 14 8 3 19 17 4 30 5 4 3 80
20111201 4 15 11 9 5 23 14 3 22 6 4 4 82
20120101 6 15 13 10 4 21 11 2 26 6 4 4 79
20120201 8 9 15 9 4 21 11 1 30 8 3 5 86
20120301 6 9 10 11 6 25 10 3 29 6 4 8 83
20120401 6 8 8 8 5 24 6 3 24 8 3 7 83
20120501 6 10 14 8 5 29 11 4 5 5 6 87
20120601 4 10 13 34 3 9 85
20120701 4 13 11 32 3 11 87
20120801 23 32 24 15 69 23 12 14 53 51
20120901 15 19 18 12 65 12 11 7 9 55 41
20121001 14 41 17 16 68 17 18 16 56 53
20121101 9 14 9 9 66 15 5 10 73 31
20121201 9 23 15 12 63 11 7 7 27 25 55
20130101 12 9 64 10 7 7 16 30 50
20130201 10 9 5 27 81 2 6 8 5 18 8
20130301 19 8 12 23 82 3 6 10 7 22 9
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Issues Ratings</title>
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line,
.axis1 path,
.axis1 line {
fill: none;
stroke: #E6E7E8;
shape-rendering: crispEdges;
}
.x.axis path, .x.axis1 path {
display: none;
}
.line {
fill: none;
stroke-width: 1.5px;
}
.legend-box {
cursor: pointer;
}
#mouse-tracker {
stroke: #E6E7E8;
stroke-width: 1px;
}
.hover-line {
stroke: #E6E7E8;
fill: none;
stroke-width: 1px;
left: 10px;
shape-rendering: crispEdges;
opacity: 1e-6;
}
.hover-text {
stroke: none;
font-size: 30px;
font-weight: bold;
fill: #000000;
}
.tooltip {
font-weight: normal;
}
.brush .extent {
stroke: #FFF;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var margin = {top: 20, right: 200, bottom: 100, left: 50},
margin2 = { top: 430, right: 10, bottom: 20, left: 40 },
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom,
height2 = 500 - margin2.top - margin2.bottom;
var parseDate = d3.time.format("%Y%m%d").parse;
var bisectDate = d3.bisector(function(d) { return d.date; }).left;
var xScale = d3.time.scale()
.range([0, width]),
xScale2 = d3.time.scale()
.range([0, width]); // Duplicate xScale for brushing ref later
var yScale = d3.scale.linear()
.range([height, 0]);
// 40 Custom DDV colors
var color = d3.scale.ordinal().range(["#48A36D", "#56AE7C", "#64B98C", "#72C39B", "#80CEAA", "#80CCB3", "#7FC9BD", "#7FC7C6", "#7EC4CF", "#7FBBCF", "#7FB1CF", "#80A8CE", "#809ECE", "#8897CE", "#8F90CD", "#9788CD", "#9E81CC", "#AA81C5", "#B681BE", "#C280B7", "#CE80B0", "#D3779F", "#D76D8F", "#DC647E", "#E05A6D", "#E16167", "#E26962", "#E2705C", "#E37756", "#E38457", "#E39158", "#E29D58", "#E2AA59", "#E0B15B", "#DFB95C", "#DDC05E", "#DBC75F", "#E3CF6D", "#EAD67C", "#F2DE8A"]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom"),
xAxis2 = d3.svg.axis() // xAxis for brush slider
.scale(xScale2)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left");
var line = d3.svg.line()
.interpolate("basis")
.x(function(d) { return xScale(d.date); })
.y(function(d) { return yScale(d.rating); })
.defined(function(d) { return d.rating; }); // Hiding line value defaults of 0 for missing data
var maxY; // Defined later to update yAxis
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom) //height + margin.top + margin.bottom
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Create invisible rect for mouse tracking
svg.append("rect")
.attr("width", width)
.attr("height", height)
.attr("x", 0)
.attr("y", 0)
.attr("id", "mouse-tracker")
.style("fill", "white");
//for slider part-----------------------------------------------------------------------------------
var context = svg.append("g") // Brushing context box container
.attr("transform", "translate(" + 0 + "," + 410 + ")")
.attr("class", "context");
//append clip path for lines plotted, hiding those part out of bounds
svg.append("defs")
.append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
//end slider part-----------------------------------------------------------------------------------
d3.tsv("data.tsv", function(error, data) {
color.domain(d3.keys(data[0]).filter(function(key) { // Set the domain of the color ordinal scale to be all the csv headers except "date", matching a color to an issue
return key !== "date";
}));
data.forEach(function(d) { // Make every date in the csv data a javascript date object format
d.date = parseDate(d.date);
});
var categories = color.domain().map(function(name) { // Nest the data into an array of objects with new keys
return {
name: name, // "name": the csv headers except date
values: data.map(function(d) { // "values": which has an array of the dates and ratings
return {
date: d.date,
rating: +(d[name]),
};
}),
visible: (name === "Unemployment" ? true : false) // "visible": all false except for economy which is true.
};
});
xScale.domain(d3.extent(data, function(d) { return d.date; })); // extent = highest and lowest points, domain is data, range is bouding box
yScale.domain([0, 100
//d3.max(categories, function(c) { return d3.max(c.values, function(v) { return v.rating; }); })
]);
xScale2.domain(xScale.domain()); // Setting a duplicate xdomain for brushing reference later
//for slider part-----------------------------------------------------------------------------------
var brush = d3.svg.brush()//for slider bar at the bottom
.x(xScale2)
.on("brush", brushed);
context.append("g") // Create brushing xAxis
.attr("class", "x axis1")
.attr("transform", "translate(0," + height2 + ")")
.call(xAxis2);
var contextArea = d3.svg.area() // Set attributes for area chart in brushing context graph
.interpolate("monotone")
.x(function(d) { return xScale2(d.date); }) // x is scaled to xScale2
.y0(height2) // Bottom line begins at height2 (area chart not inverted)
.y1(0); // Top line of area, 0 (area chart not inverted)
//plot the rect as the bar at the bottom
context.append("path") // Path is created using svg.area details
.attr("class", "area")
.attr("d", contextArea(categories[0].values)) // pass first categories data .values to area path generator
.attr("fill", "#F1F1F2");
//append the brush for the selection of subsection
context.append("g")
.attr("class", "x brush")
.call(brush)
.selectAll("rect")
.attr("height", height2) // Make brush rects same height
.attr("fill", "#E6E7E8");
//end slider part-----------------------------------------------------------------------------------
// draw line graph
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("x", -10)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Issues Rating");
var issue = svg.selectAll(".issue")
.data(categories) // Select nested data and append to new svg group elements
.enter().append("g")
.attr("class", "issue");
issue.append("path")
.attr("class", "line")
.style("pointer-events", "none") // Stop line interferring with cursor
.attr("id", function(d) {
return "line-" + d.name.replace(" ", "").replace("/", ""); // Give line id of line-(insert issue name, with any spaces replaced with no spaces)
})
.attr("d", function(d) {
return d.visible ? line(d.values) : null; // If array key "visible" = true then draw line, if not then don't
})
.attr("clip-path", "url(#clip)")//use clip path to make irrelevant part invisible
.style("stroke", function(d) { return color(d.name); });
// draw legend
var legendSpace = 450 / categories.length; // 450/number of issues (ex. 40)
issue.append("rect")
.attr("width", 10)
.attr("height", 10)
.attr("x", width + (margin.right/3) - 15)
.attr("y", function (d, i) { return (legendSpace)+i*(legendSpace) - 8; }) // spacing
.attr("fill",function(d) {
return d.visible ? color(d.name) : "#F1F1F2"; // If array key "visible" = true then color rect, if not then make it grey
})
.attr("class", "legend-box")
.on("click", function(d){ // On click make d.visible
d.visible = !d.visible; // If array key for this data selection is "visible" = true then make it false, if false then make it true
maxY = findMaxY(categories); // Find max Y rating value categories data with "visible"; true
yScale.domain([0,maxY]); // Redefine yAxis domain based on highest y value of categories data with "visible"; true
svg.select(".y.axis")
.transition()
.call(yAxis);
issue.select("path")
.transition()
.attr("d", function(d){
return d.visible ? line(d.values) : null; // If d.visible is true then draw line for this d selection
})
issue.select("rect")
.transition()
.attr("fill", function(d) {
return d.visible ? color(d.name) : "#F1F1F2";
});
})
.on("mouseover", function(d){
d3.select(this)
.transition()
.attr("fill", function(d) { return color(d.name); });
d3.select("#line-" + d.name.replace(" ", "").replace("/", ""))
.transition()
.style("stroke-width", 2.5);
})
.on("mouseout", function(d){
d3.select(this)
.transition()
.attr("fill", function(d) {
return d.visible ? color(d.name) : "#F1F1F2";});
d3.select("#line-" + d.name.replace(" ", "").replace("/", ""))
.transition()
.style("stroke-width", 1.5);
})
issue.append("text")
.attr("x", width + (margin.right/3))
.attr("y", function (d, i) { return (legendSpace)+i*(legendSpace); }) // (return (11.25/2 =) 5.625) + i * (5.625)
.text(function(d) { return d.name; });
// Hover line
var hoverLineGroup = svg.append("g")
.attr("class", "hover-line");
var hoverLine = hoverLineGroup // Create line with basic attributes
.append("line")
.attr("id", "hover-line")
.attr("x1", 10).attr("x2", 10)
.attr("y1", 0).attr("y2", height + 10)
.style("pointer-events", "none") // Stop line interferring with cursor
.style("opacity", 1e-6); // Set opacity to zero
var hoverDate = hoverLineGroup
.append('text')
.attr("class", "hover-text")
.attr("y", height - (height-40)) // hover date text position
.attr("x", width - 150) // hover date text position
.style("fill", "#E6E7E8");
var columnNames = d3.keys(data[0]) //grab the key values from your first data row
//these are the same as your column names
.slice(1); //remove the first column name (`date`);
var focus = issue.select("g") // create group elements to house tooltip text
.data(columnNames) // bind each column name date to each g element
.enter().append("g") //create one <g> for each columnName
.attr("class", "focus");
focus.append("text") // http://stackoverflow.com/questions/22064083/d3-js-multi-series-chart-with-y-value-tracking
.attr("class", "tooltip")
.attr("x", width + 20) // position tooltips
.attr("y", function (d, i) { return (legendSpace)+i*(legendSpace); }); // (return (11.25/2 =) 5.625) + i * (5.625) // position tooltips
// Add mouseover events for hover line.
d3.select("#mouse-tracker") // select chart plot background rect #mouse-tracker
.on("mousemove", mousemove) // on mousemove activate mousemove function defined below
.on("mouseout", function() {
hoverDate
.text(null) // on mouseout remove text for hover date
d3.select("#hover-line")
.style("opacity", 1e-6); // On mouse out making line invisible
});
function mousemove() {
var mouse_x = d3.mouse(this)[0]; // Finding mouse x position on rect
var graph_x = xScale.invert(mouse_x); //
//var mouse_y = d3.mouse(this)[1]; // Finding mouse y position on rect
//var graph_y = yScale.invert(mouse_y);
//console.log(graph_x);
var format = d3.time.format('%b %Y'); // Format hover date text to show three letter month and full year
hoverDate.text(format(graph_x)); // scale mouse position to xScale date and format it to show month and year
d3.select("#hover-line") // select hover-line and changing attributes to mouse position
.attr("x1", mouse_x)
.attr("x2", mouse_x)
.style("opacity", 1); // Making line visible
// Legend tooltips // http://www.d3noob.org/2014/07/my-favourite-tooltip-method-for-line.html
var x0 = xScale.invert(d3.mouse(this)[0]), /* d3.mouse(this)[0] returns the x position on the screen of the mouse. xScale.invert function is reversing the process that we use to map the domain (date) to range (position on screen). So it takes the position on the screen and converts it into an equivalent date! */
i = bisectDate(data, x0, 1), // use our bisectDate function that we declared earlier to find the index of our data array that is close to the mouse cursor
/*It takes our data array and the date corresponding to the position of or mouse cursor and returns the index number of the data array which has a date that is higher than the cursor position.*/
d0 = data[i - 1],
d1 = data[i],
/*d0 is the combination of date and rating that is in the data array at the index to the left of the cursor and d1 is the combination of date and close that is in the data array at the index to the right of the cursor. In other words we now have two variables that know the value and date above and below the date that corresponds to the position of the cursor.*/
d = x0 - d0.date > d1.date - x0 ? d1 : d0;
/*The final line in this segment declares a new array d that is represents the date and close combination that is closest to the cursor. It is using the magic JavaScript short hand for an if statement that is essentially saying if the distance between the mouse cursor and the date and close combination on the left is greater than the distance between the mouse cursor and the date and close combination on the right then d is an array of the date and close on the right of the cursor (d1). Otherwise d is an array of the date and close on the left of the cursor (d0).*/
//d is now the data row for the date closest to the mouse position
focus.select("text").text(function(columnName){
//because you didn't explictly set any data on the <text>
//elements, each one inherits the data from the focus <g>
return (d[columnName]);
});
};
//for brusher of the slider bar at the bottom
function brushed() {
xScale.domain(brush.empty() ? xScale2.domain() : brush.extent()); // If brush is empty then reset the Xscale domain to default, if not then make it the brush extent
svg.select(".x.axis") // replot xAxis with transition when brush used
.transition()
.call(xAxis);
maxY = findMaxY(categories); // Find max Y rating value categories data with "visible"; true
yScale.domain([0,maxY]); // Redefine yAxis domain based on highest y value of categories data with "visible"; true
svg.select(".y.axis") // Redraw yAxis
.transition()
.call(yAxis);
issue.select("path") // Redraw lines based on brush xAxis scale and domain
.transition()
.attr("d", function(d){
return d.visible ? line(d.values) : null; // If d.visible is true then draw line for this d selection
});
};
}); // End Data callback function
function findMaxY(data){ // Define function "findMaxY"
var maxYValues = data.map(function(d) {
if (d.visible){
return d3.max(d.values, function(value) { // Return max rating value
return value.rating; })
}
});
return d3.max(maxYValues);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment