kcp_pyramid_by_age.html 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Pyramid Chart By Age</title>
  5. <link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" />
  6. <link rel="stylesheet" type="text/css" href="examples.min.css" />
  7. <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.min.css" />
  8. <link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemejqPlot.min.css" />
  9. <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]-->
  10. <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  11. </head>
  12. <body>
  13. <div id="header">
  14. <div class="nav">
  15. <a class="nav" href="../../../index.php"><span>&gt;</span>Home</a>
  16. <a class="nav" href="../../../docs/"><span>&gt;</span>Docs</a>
  17. <a class="nav" href="../../download/"><span>&gt;</span>Download</a>
  18. <a class="nav" href="../../../info.php"><span>&gt;</span>Info</a>
  19. <a class="nav" href="../../../donate.php"><span>&gt;</span>Donate</a>
  20. </div>
  21. </div>
  22. <div class="colmask leftmenu">
  23. <div class="colleft">
  24. <div class="col1" id="example-content">
  25. <!-- Example scripts go here -->
  26. <link class="include" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" rel="Stylesheet" />
  27. <link href="colorpicker/jquery.colorpicker.css" rel="stylesheet" type="text/css"/>
  28. <style type="text/css">
  29. .quintile-outer-container {
  30. width: 97%;
  31. height: 97%;
  32. margin: auto;
  33. }
  34. .jqplot-chart {
  35. height: 600px;
  36. }
  37. .quintile-toolbar .ui-icon {
  38. float: right;
  39. margin: 3px 5px;
  40. }
  41. table.stats-table td, table.highlighted-stats-table td {
  42. background-color: rgb(230, 230, 230);
  43. padding: 0.5em;
  44. }
  45. col.label {
  46. width: 14em;
  47. }
  48. col.value {
  49. width: 7em;
  50. }
  51. td.quintile-value {
  52. width: 7em;
  53. text-align: right;
  54. }
  55. table.stats-table td.tooltip-header, table.highlighted-stats-table td.tooltip-header {
  56. background-color: rgb(200, 200, 200);
  57. }
  58. table.stats-table, table.highlighted-stats-table, td.contour-cell {
  59. font-size: 0.7em;
  60. }
  61. td.contour-cell {
  62. height: 1.5em;
  63. padding-left: 20px;
  64. padding-bottom: 1.5em;
  65. }
  66. table.highlighted-stats-table {
  67. margin-top: 15px;
  68. }
  69. div.stats-cell div.input {
  70. font-size: 0.7em;
  71. margin-top: 1.5em;
  72. }
  73. div.content-container {
  74. padding-left: 230px; /* LC width */
  75. padding-right: 300px; /* RC width */
  76. height: 100%;
  77. }
  78. div.content-container .column {
  79. position: relative;
  80. float: left;
  81. }
  82. div.controls {
  83. width: 170px; /* LC width */
  84. right: 230px; /* LC width */
  85. padding-left: 30px;
  86. padding-right: 30px;
  87. margin-left: -100%;
  88. margin-top: 30px;
  89. }
  90. div.chart-cell {
  91. width: 100%;
  92. height: 100%;
  93. }
  94. div.stats-cell {
  95. width: 270px; /* RC width */
  96. margin-right: -300px; /* RC width */
  97. padding-right: 30px;
  98. margin-top: 30px;
  99. }
  100. div.controls, div.controls select {
  101. font-size: 0.8em;
  102. }
  103. div.controls li {
  104. list-style-type: none;
  105. }
  106. div.controls ul {
  107. margin-top: 0.5em;
  108. padding-left: 0.2em;
  109. }
  110. div.overlay-chart-container {
  111. display: none;
  112. z-index: 11;
  113. position: fixed;
  114. width: 800px;
  115. left: 50%;
  116. margin-left: -400px;
  117. background-color: white;
  118. }
  119. div.overlay-chart-container div.ui-icon {
  120. float: right;
  121. margin: 3px 5px;
  122. }
  123. div.overlay-shadow {
  124. display: none;
  125. z-index: 10;
  126. background-color: rgba(0, 0, 0, 0.8);
  127. position: fixed;
  128. top: 0px;
  129. left: 0px;
  130. width: 100%;
  131. height: 100%;
  132. }
  133. div.ui-colorpicker div.ui-dialog-titlebar {
  134. padding: 0.1em 0.3em;
  135. }
  136. input.color {
  137. display: none;
  138. }
  139. div.colorpicker-container span {
  140. padding: 3px;
  141. }
  142. div.quintile-content {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. @media print {
  147. div.stats-cell {
  148. vertical-align: top;
  149. padding-top: 35px;
  150. }
  151. table.stats-table, table.stats-table td {
  152. color: #aaaaaa;
  153. border: 1px solid #bbbbbb;
  154. border-collapse: collapse;
  155. }
  156. table.stats-table tr {
  157. font-family: Verdana,Arial,sans-serif;
  158. /*font-size: 0.7em;*/
  159. }
  160. }
  161. </style>
  162. <div class="overlay-shadow"></div>
  163. <div class="overlay-chart-container ui-corner-all">
  164. <div class="overlay-chart-container-header ui-widget-header ui-corner-top">Right click the image to Copy or Save As...<div class="ui-icon ui-icon-closethick"></div></div>
  165. <div class="overlay-chart-container-content ui-corner-bottom"></div>
  166. </div>
  167. <div class="quintile-outer-container ui-widget ui-corner-all">
  168. <div class="quintile-toolbar ui-widget-header ui-corner-top">
  169. <span class="quintile-title">Income Level:</span>
  170. </div>
  171. <div class="quintile-content ui-widget-content ui-corner-bottom">
  172. <div class="content-container">
  173. <div class="chart-cell column">
  174. <div id="agesChart" class="jqplot-chart"></div>
  175. </div>
  176. <div class="controls column">
  177. <table>
  178. <tr>
  179. <td>
  180. Axes:
  181. </td>
  182. <td>
  183. <select name="axisPosition">
  184. <option value="both">Left &amp; Right</option>
  185. <option value = "left">Left</option>
  186. <option value = "right">Right</option>
  187. <option value = "mid">Mid</option>
  188. </select>
  189. </td>
  190. </tr>
  191. <tr>
  192. <td>
  193. Colors:
  194. </td>
  195. <td>
  196. <ul>
  197. <li><input class="color" type="color" id="colorMale" value="#526D2C" /> Male</li>
  198. <li><input class="color" type="color" id="colorFemale" value="#77933C" /> Female</li>
  199. <li><input class="color" type="color" id="colorBackground" value="#ffffff" /> Background</li>
  200. <li><input class="color" type="color" id="colorPlotBands" value="f5ebd7" /> Plot Bands</li>
  201. </ul>
  202. </td>
  203. </tr>
  204. <tr>
  205. <td>
  206. Grids:
  207. </td>
  208. <td>
  209. <ul>
  210. <li><input name="gridsVertical" value="vertical" type="checkbox" />Vertical</li>
  211. <li><input name="gridsHorizontal" value="horizontal" type="checkbox" />Horizontal</li>
  212. <li><input name="showMinorTicks" value="true" type="checkbox" checked />Only major</li>
  213. <li><input name="plotBands" value="true" type="checkbox" checked />Plot Bands</li>
  214. </ul>
  215. </td>
  216. </tr>
  217. <tr>
  218. <td colspan="2">
  219. <ul>
  220. <li><input name="barPadding" value="2" type="checkbox" checked />Gap between bars</li>
  221. <!-- value for showContour is speed at which to fade lines in/out -->
  222. <li><input name="showContour" value="500" type="checkbox" />Comparison Line</li>
  223. </ul>
  224. </td>
  225. </tr>
  226. </table>
  227. </div>
  228. <div class="stats-cell column">
  229. <table class="stats-table">
  230. <colgroup>
  231. <col class="label">
  232. <col class="value">
  233. </colgroup>
  234. <tbody>
  235. <tr>
  236. <td class="ui-corner-tl">Mean Age:</td>
  237. <td class="quintile-value summary-meanAge ui-corner-tr"></td>
  238. </tr>
  239. <tr>
  240. <td>Sex Ratio:</td>
  241. <td class="quintile-value summary-sexRatio"></td>
  242. </tr>
  243. <tr>
  244. <td>Age Dependency Ratio:</td>
  245. <td class="quintile-value summary-ageDependencyRatio"></td>
  246. </tr>
  247. <tr>
  248. <td>Population, Total:</td>
  249. <td class="quintile-value summary-populationTotal"></td>
  250. </tr>
  251. <tr>
  252. <td>Population, Male:</td>
  253. <td class="quintile-value summary-populationMale"></td>
  254. </tr>
  255. <tr>
  256. <td class="ui-corner-bl">Population, Female:</td>
  257. <td class="quintile-value summary-populationFemale ui-corner-br"></td>
  258. </tr>
  259. </tbody>
  260. </table>
  261. <table class="highlighted-stats-table">
  262. <colgroup>
  263. <col class="label">
  264. <col class="value">
  265. </colgroup>
  266. <tbody>
  267. <tr class="tooltip-header">
  268. <td class="tooltip-header ui-corner-top" colspan="2">Highlighted Age: <span class="tooltip-item tooltipAge">&nbsp;</span></td>
  269. </tr>
  270. <tr>
  271. <td>Population, Male: </td>
  272. <td class="quintile-value"><span class="tooltip-item tooltipMale">&nbsp;</span></td>
  273. </tr>
  274. <tr>
  275. <td>Population, Female: </td>
  276. <td class="quintile-value"><span class="tooltip-item tooltipFemale">&nbsp;</span></td>
  277. </tr>
  278. <tr>
  279. <td class="ui-corner-bl">Sex Ratio: </td>
  280. <td class="quintile-value ui-corner-br"><span class="tooltip-item tooltipRatio">&nbsp;</span></td>
  281. </tr>
  282. <tbody>
  283. </table>
  284. </div>
  285. </div>
  286. </div>
  287. </div>
  288. <script class="code" type="text/javascript">
  289. $(document).ready(function(){
  290. // if browser supports canvas, show additional toolbar icons
  291. if (!$.jqplot.use_excanvas) {
  292. $('div.quintile-toolbar').append('<div class="ui-icon ui-icon-image"></div><div class="ui-icon ui-icon-print"></div>');
  293. }
  294. // for this demo, all data is same for each quintile.
  295. // could do something like this to get the index of the quintile.
  296. // <!-- var quintileIndex = parseInt(< ? php echo $_GET["qidx"]; ? >); -->
  297. var male;
  298. var female;
  299. var summaryTable;
  300. var sexRatios;
  301. var jsondata = [[1043353182,539695335,503657847,28.24,27.51,29.01,51.78],
  302. [0.0085318435343400800,0.0088774027062416400,0.0094714560875224100,0.0101640893891056000,0.0108249758696292000,0.0113773174183149000,0.0117954271696904000,0.0120868766491156000,0.0122726357410028000,0.0123620512208843000,0.0124092312631522000,0.0123929933989534000,0.0123170841477326000,0.0121788940682660000,0.0119848553256476000,0.0117367932349178000,0.0114334768233470000,0.0110840887113746000,0.0107005336950161000,0.0102889073661635000,0.0098746874267631800,0.0094727992165526500,0.0091066817836288100,0.0087853078056091400,0.0085176451289595700,0.0082955898249666400,0.0081021034227657000,0.0079410857437656400,0.0078129432771183200,0.0077041517746791700,0.0076076629996558600,0.0075063773837400400,0.0074212932416191700,0.0073577960797626100,0.0073199937766648000,0.0072872222696609900,0.0072249036551971000,0.0071436496521446000,0.0070535868312601700,0.0069442503777637000,0.0068032069975035000,0.0066093294501292200,0.0063936409488174700,0.0061768176372133200,0.0059737878831400300,0.0057724507581444500,0.0055456647375558400,0.0053139201135624000,0.0050952395722700100,0.0048873227886988200,0.0046839194356973000,0.0044709211871979300,0.0042683374557587400,0.0040886232834079100,0.0039394433696905200,0.0038097165950705600,0.0036797119436340500,0.0035595490798891500,0.0034559622921317600,0.0033586853733251200,0.0032515219944251700,0.0031141174480235800,0.0029601056879342400,0.0027997057390388600,0.0026388958299152400,0.0024706340765107900,0.0022829305753990900,0.0020900571013307600,0.0019037152224417700,0.0017251049256371200,0.0015499961243315000,0.0013709889555399900,0.0011982773790103000,0.0010401790931594200,0.0009015220565900700,0.0007812832602556460,0.0006749752626942340,0.0005833580512023270,0.0005061657847658260,0.0004399544894590220,0.0003808034210932470,0.0003273788998735520,0.0002794993115460400,0.0002369793671257210,0.0001995479850687680,0.0001668101805315270,0.0001383186716039340,0.0001138075253115040,0.0000929924552954457,0.0000755223736670678,0.0000610047525059652,0.0000490638302928227,0.0000396489252832302,0.0000330891826825378,0.0000281195284929135,0.0001070412478036410],
  303. [0.0071192629623232800,0.0072839317935624000,0.0075693293189514500,0.0079091875498352200,0.0082360857829773300,0.0084979038169712600,0.0086893986451354100,0.0088353986277422900,0.0089633895658643000,0.0090878796761182500,0.0092337667384807200,0.0093792123312149900,0.0095192745279032600,0.0096463104169553400,0.0097588790000607600,0.0098544841215461300,0.0099282199747865200,0.0099763812248601700,0.0099957597226035700,0.0099801585489242500,0.0099375446097938400,0.0098709094654945100,0.0097926096630396900,0.0097014318757340600,0.0095968423362564000,0.0094699215837397400,0.0093120985109391200,0.0091337644254482100,0.0089445678055607600,0.0087423328014590000,0.0085321350430430500,0.0083104164267343500,0.0081040369311665900,0.0079207770770160300,0.0077675098774536000,0.0076284130950824500,0.0074765938644635800,0.0073237591351693500,0.0071772210497332700,0.0070244435483804400,0.0068550745015274400,0.0066526057090785200,0.0064404461001358000,0.0062305720357510500,0.0060342707683446500,0.0058408705961082800,0.0056264339860478000,0.0054065565344313600,0.0051920462742280000,0.0049765895152515200,0.0047558832991186200,0.0045207003388048400,0.0042899070487080500,0.0040745089551306800,0.0038817655555785800,0.0037053224400247200,0.0035332134254902200,0.0033727187145046400,0.0032284905944481100,0.0030937679725170100,0.0029582187048090100,0.0028081834596732200,0.0026513461722362800,0.0024926069125082600,0.0023353006048059200,0.0021744630786167700,0.0020021420693961100,0.0018298895084829500,0.0016671380010344600,0.0015153637133401800,0.0013712248188900700,0.0012284616818527500,0.0010934572254154500,0.0009707133813897040,0.0008622603131043950,0.0007661899219731710,0.0006786114871838230,0.0006005435486257860,0.0005322956370150040,0.0004715229254612440,0.0004158721219136000,0.0003645948643149670,0.0003176904909297340,0.0002751152300590630,0.0002367021156783720,0.0002021700726755280,0.0001712214234345020,0.0001437557719387760,0.0001197138111336940,0.0000989925882290494,0.0000814263200020563,0.0000667991474109870,0.0000549164545704749,0.0000455518367647343,0.0000384480445034309,0.0001437755914949950],
  304. [1.284165231,1.3059697282,1.3408259576,1.3770498469,1.4083776842,1.4346340126,1.4545779876,1.4658887137,1.4671638972,1.457608962,1.4400548643,1.4158684686,1.3864911961,1.3528812542,1.3159697978,1.27622903,1.2340137083,1.1905291022,1.1471037258,1.1047013276,1.0647737249,1.0283340659,0.9964942039,0.9703629438,0.9510519527,0.9386721807,0.932316307,0.9316292996,0.9359838821,0.9443012277,0.9554470086,0.9678781103,0.9812761433,0.9953894103,1.0098153246,1.0236249732,1.035479081,1.0451994053,1.0530930686,1.0593183708,1.0634438538,1.0645809137,1.0637641578,1.0623066923,1.0608111193,1.0589993944,1.0561690641,1.0531914677,1.0515722425,1.052330754,1.0553372965,1.0597522653,1.0661637808,1.0752634417,1.0874733411,1.1017415355,1.1159815378,1.1309096828,1.1470504754,1.1633078085,1.1777943775,1.1882903501,1.1963378464,1.2035708256,1.2108560457,1.2175013424,1.2218302494,1.2239011525,1.223611334,1.2198647763,1.2112533925,1.1958739376,1.1742717733,1.1482333683,1.1203430352,1.0926602484,1.0658097999,1.040887396,1.0189501507,0.9998112064,0.9811922123,0.9621730704,0.9427349027,0.9230154312,0.903354613,0.8841353287,0.8656369091,0.8483181293,0.8323701879,0.8174967062,0.8028084248,0.7870522949,0.7736454722,0.7783827557,0.7836945697,0.7977724963],
  305. [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,"95+", ""]];
  306. // the "x" values from the data will go into the ticks array.
  307. // ticks should be strings for this case where we have values like "75+"
  308. var ticks = jsondata[4];
  309. $('td.summary-meanAge').each(function(index) {
  310. $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][3]));
  311. });
  312. $('td.summary-sexRatio').each(function(index) {
  313. $(this).html($.jqplot.sprintf('%5.2f', jsondata[3][0]));
  314. });
  315. $('td.summary-ageDependencyRatio').each(function(index) {
  316. $(this).html($.jqplot.sprintf('%5.2f', jsondata[0][6]));
  317. });
  318. $('td.summary-populationTotal').each(function(index) {
  319. $(this).html($.jqplot.sprintf("%'d", jsondata[0][0]));
  320. });
  321. $('td.summary-populationMale').each(function(index) {
  322. $(this).html($.jqplot.sprintf("%'d", jsondata[0][1]));
  323. });
  324. $('td.summary-populationFemale').each(function(index) {
  325. $(this).html($.jqplot.sprintf("%'d", jsondata[0][2]));
  326. });
  327. // These two variables should be removed outside of the jqplot.com example environment.
  328. $.jqplot._noToImageButton = true;
  329. $.jqplot._noCodeBlock = true;
  330. // Custom color arrays are set up for each series to get the look that is desired.
  331. // Two color arrays are created for the default and optional color which the user can pick.
  332. var greenColors = ["#526D2C", "#77933C", "#C57225", "#C57225"];
  333. var blueColors = ["#3F7492", "#4F9AB8", "#C57225", "#C57225"];
  334. // To accomodate changing y axis, need to keep track of plot options.
  335. // changing axes will require recreating the plot, so need to keep
  336. // track of state changes.
  337. var plotOptions = {
  338. // We set up a customized title which acts as labels for the left and right sides of the pyramid.
  339. title: {
  340. text: '<span style="margin-left:25%;">Male</span><span style="margin-left:33%;">Female</span>',
  341. textAlign: 'left'
  342. },
  343. // by default, the series will use the green color scheme.
  344. seriesColors: greenColors,
  345. grid: {
  346. drawBorder: false,
  347. shadow: false,
  348. background: "#ffffff",
  349. rendererOptions: {
  350. // plotBands is an option of the pyramidGridRenderer.
  351. // it will put banding at starting at a specified value
  352. // along the y axis with an adjustable interval.
  353. plotBands: {
  354. show: true,
  355. interval: 10,
  356. color: 'rgb(245, 235, 215)'
  357. }
  358. }
  359. },
  360. // This makes the effective starting value of the axes 0 instead of 1.
  361. // For display, the y axis will use the ticks we supplied.
  362. defaultAxisStart: 0,
  363. seriesDefaults: {
  364. renderer: $.jqplot.PyramidRenderer,
  365. rendererOptions: {
  366. barPadding: 1.5,
  367. offsetBars: true
  368. },
  369. yaxis: "yaxis",
  370. shadow: false
  371. },
  372. // We have 4 series, the left and right pyramid bars and
  373. // the left and rigt overlay lines.
  374. series: [
  375. // For pyramid plots, the default side is right.
  376. // We want to override here to put first set of bars
  377. // on left.
  378. {
  379. rendererOptions:{
  380. side: "left",
  381. synchronizeHighlight: 1
  382. }
  383. },
  384. {
  385. yaxis: "y2axis",
  386. rendererOptions: {
  387. synchronizeHighlight: 0
  388. }
  389. },
  390. {
  391. rendererOptions: {
  392. fill: false,
  393. side: 'left'
  394. }
  395. },
  396. {
  397. yaxis: 'y2axis',
  398. rendererOptions: {
  399. fill: false
  400. }
  401. }
  402. ],
  403. axesDefaults: {
  404. tickOptions: {
  405. showGridline: false
  406. },
  407. pad: 0,
  408. rendererOptions: {
  409. baselineWidth: 2
  410. }
  411. },
  412. // Set up all the y axes, since users are allowed to switch between them.
  413. // The only axis that will show is the one that the series are "attached" to.
  414. // We need the appropriate options for the others for when the user switches.
  415. axes: {
  416. xaxis: {
  417. tickOptions: {
  418. formatter: $.jqplot.PercentTickFormatter,
  419. formatString: '%.1f%%'
  420. }
  421. },
  422. yaxis: {
  423. label: "Age",
  424. // Use canvas label renderer to get rotated labels.
  425. labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
  426. // include empty tick options, they will be used
  427. // as users set options with plot controls.
  428. tickOptions: {},
  429. showMinorTicks: false,
  430. tickInterval: 5,
  431. ticks: ticks,
  432. rendererOptions: {
  433. tickSpacingFactor: 15,
  434. category: false
  435. }
  436. },
  437. yMidAxis: {
  438. label: "Age",
  439. // include empty tick options, they will be used
  440. // as users set options with plot controls.
  441. tickOptions: {},
  442. showMinorTicks: false,
  443. tickInterval: 5,
  444. ticks: ticks,
  445. rendererOptions: {
  446. tickSpacingFactor: 15,
  447. category: false
  448. }
  449. },
  450. y2axis: {
  451. label: "Age",
  452. // Use canvas label renderer to get rotated labels.
  453. labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
  454. // include empty tick options, they will be used
  455. // as users set options with plot controls.
  456. tickOptions: {},
  457. showMinorTicks: false,
  458. tickInterval: 5,
  459. ticks: ticks,
  460. rendererOptions: {
  461. tickSpacingFactor: 15,
  462. category: false
  463. }
  464. }
  465. }
  466. };
  467. // resize the chart container to fill the space
  468. $('#agesChart').height($('div.chart-cell').height()*0.96);
  469. $('#agesChart').width($('div.chart-cell').width()*0.97);
  470. // $('#agesChart').jqplot([jsondata[1], jsondata[2]], plotOptions);
  471. $.jqplot.config.addDomReference = true;
  472. var plot1 = $.jqplot('agesChart', [jsondata[1], jsondata[2]], plotOptions);
  473. $(window).resize (function(event, ui) {
  474. // pass in resetAxes: true option to get rid of old ticks and axis properties
  475. // which should be recomputed based on new plot size.
  476. $('#agesChart').height($('div.chart-cell').height()*0.96);
  477. $('#agesChart').width($('div.chart-cell').width()*0.97);
  478. plot1.replot( { resetAxes: true } );
  479. });
  480. // initialize form elements
  481. // set these before attaching event handlers.
  482. $("input[type=checkbox][name=gridsVertical]").attr("checked", false);
  483. $("input[type=checkbox][name=gridsHorizontal]").attr("checked", false);
  484. $("input[type=checkbox][name=showMinorTicks]").attr("checked", true);
  485. $("input[type=checkbox][name=plotBands]").attr("checked", true);
  486. $("input[type=checkbox][name=showContour]").attr("checked", true);
  487. $("input[type=checkbox][name=barPadding]").attr("checked", true);
  488. $("select[name=axisPosition]").val("both");
  489. //////
  490. // The followng functions use verbose css selectors to make
  491. // it clear exactly which elements they are binging to/operating on
  492. //////
  493. $("select[name=axisPosition]").change(function(){
  494. // this refers to the html element we are binding to.
  495. // $(this) is jQuery object on that element.
  496. var opts = {series:[{}, {}, {}, {}]};
  497. switch ($(this).val()) {
  498. case "both":
  499. opts.series[0].yaxis = "yaxis";
  500. opts.series[1].yaxis = "y2axis";
  501. opts.series[2].yaxis = "yaxis";
  502. opts.series[3].yaxis = "y2axis";
  503. break;
  504. case "left":
  505. opts.series[0].yaxis = "yaxis";
  506. opts.series[1].yaxis = "yaxis";
  507. opts.series[2].yaxis = "yaxis";
  508. opts.series[3].yaxis = "yaxis";
  509. break;
  510. case "right":
  511. opts.series[0].yaxis = "y2axis";
  512. opts.series[1].yaxis = "y2axis";
  513. opts.series[2].yaxis = "y2axis";
  514. opts.series[3].yaxis = "y2axis";
  515. break;
  516. case "mid":
  517. opts.series[0].yaxis = "yMidAxis";
  518. opts.series[1].yaxis = "yMidAxis";
  519. opts.series[2].yaxis = "yMidAxis";
  520. opts.series[3].yaxis = "yMidAxis";
  521. break;
  522. default:
  523. break;
  524. }
  525. plot1.replot(opts);
  526. });
  527. // bind to the data highlighting event to make custom tooltip:
  528. $(".jqplot-target").each(function(index){
  529. $(this).bind("jqplotDataHighlight", function(evt, seriesIndex, pointIndex, data) {
  530. // Here, assume first series is male poulation and second series is female population.
  531. // Adjust series indices as appropriate.
  532. var plot = $(this).data('jqplot');
  533. var malePopulation = Math.abs(plot.series[0].data[pointIndex][1]) * jsondata[0][1];
  534. var femalePopulation = Math.abs(plot.series[1].data[pointIndex][1]) * jsondata[0][2];
  535. var malePopulation = jsondata[1][pointIndex] * jsondata[0][1];
  536. var femalePopulation = jsondata[2][pointIndex] * jsondata[0][2];
  537. // var ratio = femalePopulation / malePopulation * 100;
  538. var ratio = jsondata[3][pointIndex];
  539. $('.tooltipMale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", malePopulation));
  540. $('.tooltipFemale').stop(true, true).fadeIn(350).html($.jqplot.sprintf("%'d", femalePopulation));
  541. $('.tooltipRatio').stop(true, true).fadeIn(350).html($.jqplot.sprintf('%5.2f', ratio));
  542. // Since we don't know which axis is rendererd and acive with out a little extra work,
  543. // just use the supplied ticks array to get the age label.
  544. $('.tooltipAge').stop(true, true).fadeIn(350).html(ticks[pointIndex]);
  545. });
  546. });
  547. // bind to the data highlighting event to make custom tooltip:
  548. $(".jqplot-target").each(function() {
  549. $(this).bind("jqplotDataUnhighlight", function(evt, seriesIndex, pointIndex, data) {
  550. // clear out all the tooltips.
  551. $(".tooltip-item").fadeOut(250);
  552. });
  553. });
  554. $('.ui-icon-print').click(function(){
  555. $(this).parent().next().print();
  556. });
  557. $("input[type=checkbox][name=gridsVertical]").change(function(){
  558. // this refers to the html element we are binding to.
  559. // $(this) is jQuery object on that element.
  560. var opts = {axes: {xaxis: {tickOptions: {showGridline: this.checked}}}};
  561. plot1.replot(opts);
  562. });
  563. $("input[type=checkbox][name=gridsHorizontal]").change(function(){
  564. // this refers to the html element we are binding to.
  565. // $(this) is jQuery object on that element.
  566. var opts = {
  567. axes: {
  568. yaxis: {
  569. tickOptions: {showGridline: this.checked}
  570. },
  571. y2axis: {
  572. tickOptions: {showGridline: this.checked}
  573. },
  574. yMidAxis: {
  575. tickOptions: {showGridline: this.checked}
  576. }
  577. }
  578. };
  579. plot1.replot(opts);
  580. });
  581. $("input[type=checkbox][name=plotBands]").change(function(){
  582. // this refers to the html element we are binding to.
  583. // $(this) is jQuery object on that element.
  584. var opts = {grid:{ rendererOptions: {plotBands: { show: this.checked}}}};
  585. plot1.replot(opts);
  586. });
  587. ////
  588. // To-Do
  589. //
  590. // initialize form elements on reload.
  591. // figure out what overlay line would be.
  592. // have to adjust ticks to do show minor.
  593. // make like kcp_pyramid.php
  594. ////
  595. $("input[type=checkbox][name=showMinorTicks]").change(function(){
  596. // this refers to the html element we are binding to.
  597. // $(this) is jQuery object on that element.
  598. var opts = {
  599. axes: {
  600. yaxis: {
  601. showMinorTicks: !this.checked
  602. },
  603. y2axis: {
  604. showMinorTicks: !this.checked
  605. },
  606. yMidAxis: {
  607. showMinorTicks: !this.checked
  608. }
  609. }
  610. };
  611. plot1.replot(opts);
  612. });
  613. $("input[type=checkbox][name=barPadding]").change(function(){
  614. // this refers to the html element we are binding to.
  615. // $(this) is jQuery object on that element.
  616. if (this.checked) {
  617. var val = parseFloat($(this).val());
  618. var opts = {
  619. seriesDefaults: {
  620. rendererOptions: {
  621. barPadding: val
  622. }
  623. }
  624. };
  625. }
  626. else {
  627. var opts = {
  628. seriesDefaults: {
  629. rendererOptions: {
  630. barPadding: 0
  631. }
  632. }
  633. };
  634. }
  635. plot1.replot(opts);
  636. });
  637. $('.ui-icon-image').each(function() {
  638. $(this).bind('click', function(evt) {
  639. var chart = $(this).closest('div.quintile-outer-container').find('div.jqplot-target');
  640. var imgelem = chart.jqplotToImageElem();
  641. var div = $('div.overlay-chart-container-content');
  642. div.empty();
  643. div.append(imgelem);
  644. $('div.overlay-shadow').fadeIn(600);
  645. div.parent().fadeIn(1000);
  646. div = null;
  647. });
  648. });
  649. $('div.overlay-chart-container-header div.ui-icon-closethick').click(function(){
  650. var div = $('div.overlay-chart-container-content');
  651. div.parent().fadeOut(600);
  652. $('div.overlay-shadow').fadeOut(1000);
  653. });
  654. function applyColors(maleColor, femaleColor, backgroundColor, bandColor) {
  655. var opts = {series:[{}, {}], grid:{rendererOptions:{plotBands:{}}}};
  656. opts.series[0].color = maleColor;
  657. opts.series[1].color = femaleColor;
  658. opts.grid.background = backgroundColor;
  659. opts.grid.rendererOptions.plotBands.color = bandColor;
  660. plot1.replot(opts);
  661. };
  662. $('#colorMale').colorpicker({
  663. colorFormat: '#HEX',
  664. showOn: 'button',
  665. buttonColorize: true,
  666. buttonImageOnly: true,
  667. parts: 'full',
  668. close: function(ui, color) {
  669. applyColors(color.formatted, plot1.series[1].color, plot1.grid.background, plot1.grid.plotBands.color);
  670. }
  671. });
  672. $('#colorFemale').colorpicker({
  673. colorFormat: '#HEX',
  674. showOn: 'button',
  675. buttonColorize: true,
  676. buttonImageOnly: true,
  677. parts: 'full',
  678. close: function(ui, color) {
  679. applyColors(plot1.series[0].color, color.formatted, plot1.grid.background, plot1.grid.plotBands.color);
  680. }
  681. });
  682. $('#colorBackground').colorpicker({
  683. colorFormat: '#HEX',
  684. showOn: 'button',
  685. buttonColorize: true,
  686. buttonImageOnly: true,
  687. parts: 'full',
  688. close: function(ui, color) {
  689. applyColors(plot1.series[0].color, plot1.series[1].color, color.formatted, plot1.grid.plotBands.color);
  690. }
  691. });
  692. $('#colorPlotBands').colorpicker({
  693. colorFormat: '#HEX',
  694. showOn: 'button',
  695. buttonColorize: true,
  696. buttonImageOnly: true,
  697. parts: 'full',
  698. close: function(ui, color) {
  699. applyColors(plot1.series[0].color, plot1.series[1].color, plot1.grid.background, color.formatted);
  700. }
  701. });
  702. });
  703. </script>
  704. <!-- End example scripts -->
  705. <!-- Don't touch this! -->
  706. <script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script>
  707. <script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script>
  708. <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script>
  709. <script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script>
  710. <!-- End Don't touch this! -->
  711. <!-- Additional plugins go here -->
  712. <script class="include" type="text/javascript" src="../plugins/jqplot.categoryAxisRenderer.min.js"></script>
  713. <!-- load the pyramidAxis and Grid renderers in production. pyramidRenderer will try to load via ajax if not present, but that is not optimal and depends on paths being set. -->
  714. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidAxisRenderer.min.js"></script>
  715. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidGridRenderer.min.js"></script>
  716. <script class="include" type="text/javascript" src="../plugins/jqplot.pyramidRenderer.min.js"></script>
  717. <script class="include" type="text/javascript" src="../plugins/jqplot.canvasTextRenderer.min.js"></script>
  718. <script class="include" type="text/javascript" src="../plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
  719. <script class="include" type="text/javascript" src="../plugins/jqplot.json2.min.js"></script>
  720. <script class="include" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
  721. <script class="include" type="text/javascript" src="kcp.print.js"></script>
  722. <script src="colorpicker/jquery.colorpicker.js"></script>
  723. <!-- End additional plugins -->
  724. </div>
  725. <div class="col2">
  726. <div class="example-link"><a class="example-link" href="data-renderers.html">AJAX and JSON Data Loading via Data Renderers</a></div>
  727. <div class="example-link"><a class="example-link" href="barLineAnimated.html">Animated Charts</a></div>
  728. <div class="example-link"><a class="example-link" href="dashboardWidget.html">Animated Dashboard Sample - Filled Line with Log Axis</a></div>
  729. <div class="example-link"><a class="example-link" href="kcp_area.html">Area Chart</a></div>
  730. <div class="example-link"><a class="example-link" href="kcp_area2.html">Area Chart 2</a></div>
  731. <div class="example-link"><a class="example-link" href="axisLabelTests.html">Axis Labels</a></div>
  732. <div class="example-link"><a class="example-link" href="axisLabelsRotatedText.html">Axis Labels and Rotated Text</a></div>
  733. <div class="example-link"><a class="example-link" href="barTest.html">Bar Charts</a></div>
  734. <div class="example-link"><a class="example-link" href="multipleBarColors.html">Bar Colors Example</a></div>
  735. <div class="example-link"><a class="example-link" href="bezierCurve.html">Bezier Curve Plots</a></div>
  736. <div class="example-link"><a class="example-link" href="blockPlot.html">Block Plots</a></div>
  737. <div class="example-link"><a class="example-link" href="bubbleChart.html">Bubble Charts</a></div>
  738. <div class="example-link"><a class="example-link" href="bubble-plots.html">Bubble Plots</a></div>
  739. <div class="example-link"><a class="example-link" href="candlestick.html">Candlestick and Open Hi Low Close Charts</a></div>
  740. <div class="example-link"><a class="example-link" href="theming.html">Chart Theming</a></div>
  741. <div class="example-link"><a class="example-link" href="fillBetweenLines.html">Charts with Fill Between Lines</a></div>
  742. <div class="example-link"><a class="example-link" href="kcp_cdf.html">Cumulative Density Function Chart</a></div>
  743. <div class="example-link"><a class="example-link" href="dashedLines.html">Dashed Lines with Smoothing</a></div>
  744. <div class="example-link"><a class="example-link" href="cursor-highlighter.html">Data Point Highlighting, Tooltips and Cursor Tracking</a></div>
  745. <div class="example-link"><a class="example-link" href="point-labels.html">Data Point labels</a></div>
  746. <div class="example-link"><a class="example-link" href="date-axes.html">Date Axes</a></div>
  747. <div class="example-link"><a class="example-link" href="dateAxisRenderer.html">Date Axes 2</a></div>
  748. <div class="example-link"><a class="example-link" href="rotatedTickLabelsZoom.html">Date Axes, Rotated Labels and Zooming</a></div>
  749. <div class="example-link"><a class="example-link" href="canvas-overlay.html">Draw Lines on Plots - Canvas Overlay</a></div>
  750. <div class="example-link"><a class="example-link" href="draw-rectangles.html">Draw Rectangles on Plots</a></div>
  751. <div class="example-link"><a class="example-link" href="kcp_engel.html">Engel Curves</a></div>
  752. <div class="example-link"><a class="example-link" href="bandedLine.html">Error Bands and Confidence Intervals</a></div>
  753. <div class="example-link"><a class="example-link" href="area.html">Filled (Area) Charts</a></div>
  754. <div class="example-link"><a class="example-link" href="axisScalingForceTickAt.html">Force Plot to Have Tick at 0 or 100</a></div>
  755. <div class="example-link"><a class="example-link" href="hiddenPlotsInTabs.html">Hidden Plots</a></div>
  756. <div class="example-link"><a class="example-link" href="customHighlighterCursorTrendline.html">Highlighting, Dragging Points, Cursor and Trend Lines</a></div>
  757. <div class="example-link"><a class="example-link" href="line-charts.html">Line Charts and Options</a></div>
  758. <div class="example-link"><a class="example-link" href="kcp_lorenz.html">Lorenz Curves</a></div>
  759. <div class="example-link"><a class="example-link" href="mekkoCharts.html">Mekko Charts</a></div>
  760. <div class="example-link"><a class="example-link" href="meterGauge.html">Meter Gauge</a></div>
  761. <div class="example-link"><a class="example-link" href="candlestick-charts.html">Open Hi Low Close and Candlestick Charts</a></div>
  762. <div class="example-link"><a class="example-link" href="pieTest.html">Pie Charts and Options</a></div>
  763. <div class="example-link"><a class="example-link" href="pieTest4.html">Pie Charts and Options 2</a></div>
  764. <div class="example-link"><a class="example-link" href="pie-donut-charts.html">Pie and Donut Charts</a></div>
  765. <div class="example-link"><a class="example-link" href="selectorSyntax.html">Plot Creation with jQuery Selectors</a></div>
  766. <div class="example-link"><a class="example-link" href="zooming.html">Plot Zooming and Cursor Control</a></div>
  767. <div class="example-link"><a class="example-link" href="kcp_pdf.html">Probability Density Function Chart</a></div>
  768. <div class="example-link"><a class="example-link" href="kcp_pyramid_by_age.html">Pyramid Chart By Age</a></div>
  769. <div class="example-link"><a class="example-link" href="kcp_pyramid.html">Pyramid Charts</a></div>
  770. <div class="example-link"><a class="example-link" href="kcp_pyramid2.html">Pyramid Charts 2</a></div>
  771. <div class="example-link"><a class="example-link" href="kcp_quintiles.html">Quintile Pyramid Charts</a></div>
  772. <div class="example-link"><a class="example-link" href="resizablePlot.html">Resizable Plots</a></div>
  773. <div class="example-link"><a class="example-link" href="rotated-tick-labels.html">Rotated Labels and Font Styling</a></div>
  774. <div class="example-link"><a class="example-link" href="smoothedLine.html">Smoothed Lines</a></div>
  775. <div class="example-link"><a class="example-link" href="bar-charts.html">Vertical and Horizontal Bar Charts</a></div>
  776. <div class="example-link"><a class="example-link" href="waterfall.html">Waterfall Charts</a></div>
  777. <div class="example-link"><a class="example-link" href="waterfall2.html">Waterfall Charts 2</a></div>
  778. <div class="example-link"><a class="example-link" href="zoomOptions.html">Zoom Options</a></div>
  779. <div class="example-link"><a class="example-link" href="zoomProxy.html">Zoom Proxy - Control one plot from another</a></div>
  780. <div class="example-link"><a class="example-link" href="zoom1.html">Zooming</a></div>
  781. <div class="example-link"><a class="example-link" href="dateAxisLogAxisZooming.html">Zooming with Date and Log Axes</a></div>
  782. </div>
  783. </div>
  784. </div>
  785. <script type="text/javascript" src="example.min.js"></script>
  786. </body>
  787. </html>