| 1 |
<!doctype> |
| 2 |
<link type="text/css" rel="stylesheet" href="../rickshaw.min.css"> |
| 3 |
<script src="../vendor/d3.min.js"></script> |
| 4 |
<script src="../vendor/d3.layout.min.js"></script> |
| 5 |
<script src="../rickshaw.min.js"></script> |
| 6 |
|
| 7 |
<style> |
| 8 |
#chart_container { |
| 9 |
display: inline-block; |
| 10 |
font-family: Arial, Helvetica, sans-serif; |
| 11 |
} |
| 12 |
#chart { |
| 13 |
float: left; |
| 14 |
} |
| 15 |
#legend { |
| 16 |
float: left; |
| 17 |
margin-left: 15px; |
| 18 |
} |
| 19 |
#offset_form { |
| 20 |
float: left; |
| 21 |
margin: 2em 0 0 15px; |
| 22 |
font-size: 13px; |
| 23 |
} |
| 24 |
#y_axis { |
| 25 |
float: left; |
| 26 |
width: 40px; |
| 27 |
} |
| 28 |
</style> |
| 29 |
|
| 30 |
<div id="chart_container"> |
| 31 |
<div id="y_axis"></div> |
| 32 |
<div id="chart"></div> |
| 33 |
<div id="legend"></div> |
| 34 |
<form id="offset_form" class="toggler"> |
| 35 |
<input type="radio" name="offset" id="lines" value="lines" checked> |
| 36 |
<label class="lines" for="lines">lines</label><br> |
| 37 |
<input type="radio" name="offset" id="stack" value="zero"> |
| 38 |
<label class="stack" for="stack">stack</label> |
| 39 |
</form> |
| 40 |
</div> |
| 41 |
|
| 42 |
<script> |
| 43 |
var palette = new Rickshaw.Color.Palette(); |
| 44 |
|
| 45 |
var graph = new Rickshaw.Graph( { |
| 46 |
element: document.querySelector("#chart"), |
| 47 |
width: 540, |
| 48 |
height: 240, |
| 49 |
renderer: 'line', |
| 50 |
series: [ |
| 51 |
{ |
| 52 |
name: "Northeast", |
| 53 |
data: [ { x: -1893456000, y: 25868573 }, { x: -1577923200, y: 29662053 }, { x: -1262304000, y: 34427091 }, { x: -946771200, y: 35976777 }, { x: -631152000, y: 39477986 }, { x: -315619200, y: 44677819 }, { x: 0, y: 49040703 }, { x: 315532800, y: 49135283 }, { x: 631152000, y: 50809229 }, { x: 946684800, y: 53594378 }, { x: 1262304000, y: 55317240 } ], |
| 54 |
color: palette.color() |
| 55 |
}, |
| 56 |
{ |
| 57 |
name: "Midwest", |
| 58 |
data: [ { x: -1893456000, y: 29888542 }, { x: -1577923200, y: 34019792 }, { x: -1262304000, y: 38594100 }, { x: -946771200, y: 40143332 }, { x: -631152000, y: 44460762 }, { x: -315619200, y: 51619139 }, { x: 0, y: 56571663 }, { x: 315532800, y: 58865670 }, { x: 631152000, y: 59668632 }, { x: 946684800, y: 64392776 }, { x: 1262304000, y: 66927001 } ], |
| 59 |
color: palette.color() |
| 60 |
}, |
| 61 |
{ |
| 62 |
name: "South", |
| 63 |
data: [ { x: -1893456000, y: 29389330 }, { x: -1577923200, y: 33125803 }, { x: -1262304000, y: 37857633 }, { x: -946771200, y: 41665901 }, { x: -631152000, y: 47197088 }, { x: -315619200, y: 54973113 }, { x: 0, y: 62795367 }, { x: 315532800, y: 75372362 }, { x: 631152000, y: 85445930 }, { x: 946684800, y: 100236820 }, { x: 1262304000, y: 114555744 } ], |
| 64 |
color: palette.color() |
| 65 |
}, |
| 66 |
{ |
| 67 |
name: "West", |
| 68 |
data: [ { x: -1893456000, y: 7082086 }, { x: -1577923200, y: 9213920 }, { x: -1262304000, y: 12323836 }, { x: -946771200, y: 14379119 }, { x: -631152000, y: 20189962 }, { x: -315619200, y: 28053104 }, { x: 0, y: 34804193 }, { x: 315532800, y: 43172490 }, { x: 631152000, y: 52786082 }, { x: 946684800, y: 63197932 }, { x: 1262304000, y: 71945553 } ], |
| 69 |
color: palette.color() |
| 70 |
} |
| 71 |
] |
| 72 |
} ); |
| 73 |
|
| 74 |
var x_axis = new Rickshaw.Graph.Axis.Time( { graph: graph } ); |
| 75 |
|
| 76 |
var y_axis = new Rickshaw.Graph.Axis.Y( { |
| 77 |
graph: graph, |
| 78 |
orientation: 'left', |
| 79 |
tickFormat: Rickshaw.Fixtures.Number.formatKMBT, |
| 80 |
element: document.getElementById('y_axis'), |
| 81 |
} ); |
| 82 |
|
| 83 |
var legend = new Rickshaw.Graph.Legend( { |
| 84 |
element: document.querySelector('#legend'), |
| 85 |
graph: graph |
| 86 |
} ); |
| 87 |
|
| 88 |
var offsetForm = document.getElementById('offset_form'); |
| 89 |
|
| 90 |
offsetForm.addEventListener('change', function(e) { |
| 91 |
var offsetMode = e.target.value; |
| 92 |
|
| 93 |
if (offsetMode == 'lines') { |
| 94 |
graph.setRenderer('line'); |
| 95 |
graph.offset = 'zero'; |
| 96 |
} else { |
| 97 |
graph.setRenderer('stack'); |
| 98 |
graph.offset = offsetMode; |
| 99 |
} |
| 100 |
graph.render(); |
| 101 |
|
| 102 |
}, false); |
| 103 |
|
| 104 |
graph.render(); |
| 105 |
|
| 106 |
</script> |