6 $title = "Pyramid Chart By Age";
9 <title
><?php
print $title ?
></title
>
11 <link
class="include" rel
="stylesheet" type
="text/css" href
="../jquery.jqplot.css" />
12 <link rel
="stylesheet" type
="text/css" href
="examples.css" />
13 <link type
="text/css" rel
="stylesheet" href
="syntaxhighlighter/styles/shCoreDefault.min.css" />
14 <link type
="text/css" rel
="stylesheet" href
="syntaxhighlighter/styles/shThemejqPlot.min.css" />
16 <!--[if lt IE
9]><script language
="javascript" type
="text/javascript" src
="../excanvas.js"></script
><![endif]-->
17 <script
class="include" type
="text/javascript" src
="../jquery.min.js"></script
>
19 <link
class="include" type
="text/css" href
="jquery-ui/css/smoothness/jquery-ui.min.css" rel
="Stylesheet" />
20 <link href
="colorpicker/jquery.colorpicker.css" rel
="stylesheet" type
="text/css"/>
22 <style type
="text/css">
35 .quintile
-outer
-container
{
46 .quintile
-toolbar
.ui
-icon
{
51 table
.stats
-table td
, table
.highlighted
-stats
-table td
{
52 background
-color
: rgb(230, 230, 230);
69 table
.stats
-table td
.tooltip
-header
, table
.highlighted
-stats
-table td
.tooltip
-header
{
70 background
-color
: rgb(200, 200, 200);
73 table
.stats
-table
, table
.highlighted
-stats
-table
, td
.contour
-cell
{
80 padding
-bottom
: 1.5em
;
83 table
.highlighted
-stats
-table
{
87 div
.stats
-cell div
.input
{
92 div
.content
-container
{
93 padding
-left
: 230px
; /* LC width */
94 padding
-right
: 300px
; /* RC width */
98 div
.content
-container
.column
{
104 width
: 170px
; /* LC width */
105 right
: 230px
; /* LC width */
118 width
: 270px
; /* RC width */
119 margin
-right
: -300px
; /* RC width */
124 div
.controls
, div
.controls select
{
129 list-style
-type
: none
;
137 div
.overlay
-chart
-container
{
144 background
-color
: white
;
147 div
.overlay
-chart
-container div
.ui
-icon
{
155 background
-color
: rgba(0, 0, 0, 0.8);
163 div
.ui
-colorpicker div
.ui
-dialog
-titlebar
{
164 padding
: 0.1em
0.3em
;
171 div
.colorpicker
-container span
{
175 div
.quintile
-content
{
187 table
.stats
-table
, table
.stats
-table td
{
189 border
: 1px solid
#bbbbbb;
190 border
-collapse
: collapse
;
193 table
.stats
-table tr
{
194 font
-family
: Verdana
,Arial
,sans
-serif
;
195 /*font-size: 0.7em;*/
205 <!-- Example scripts go here
-->
208 <div
class="overlay-shadow"></div
>
210 <div
class="overlay-chart-container ui-corner-all">
211 <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
>
212 <div
class="overlay-chart-container-content ui-corner-bottom"></div
>
215 <div
class="quintile-outer-container ui-widget ui-corner-all">
216 <div
class="quintile-toolbar ui-widget-header ui-corner-top">
217 <span
class="quintile-title">Income Level
:</span
>
219 <div
class="quintile-content ui-widget-content ui-corner-bottom">
221 <div
class="content-container">
224 <div
class="chart-cell column">
225 <div id
="agesChart" class="jqplot-chart"></div
>
228 <div
class="controls column">
235 <select name
="axisPosition">
236 <option value
="both">Left
&
; Right
</option
>
237 <option value
= "left">Left
</option
>
238 <option value
= "right">Right
</option
>
239 <option value
= "mid">Mid
</option
>
249 <li
><input
class="color" type
="color" id
="colorMale" /> Male
</li
>
250 <li
><input
class="color" type
="color" id
="colorFemale" /> Female
</li
>
251 <li
><input
class="color" type
="color" id
="colorBackground" /> Background
</li
>
252 <li
><input
class="color" type
="color" id
="colorPlotBands" /> Plot Bands
</li
>
262 <li
><input name
="gridsVertical" value
="vertical" type
="checkbox" />Vertical
</li
>
263 <li
><input name
="gridsHorizontal" value
="horizontal" type
="checkbox" />Horizontal
</li
>
264 <li
><input name
="showMinorTicks" value
="true" type
="checkbox" checked
/>Only major
</li
>
265 <li
><input name
="plotBands" value
="true" type
="checkbox" checked
/>Plot Bands
</li
>
272 <li
><input name
="barPadding" value
="2" type
="checkbox" checked
/>Gap between bars
</li
>
273 <!-- value
for showContour is speed at which to fade lines in
/out
-->
274 <li
><input name
="showContour" value
="500" type
="checkbox" />Comparison Line
</li
>
281 <div
class="stats-cell column">
282 <table
class="stats-table">
289 <td
class="ui-corner-tl">Mean Age
:</td
>
290 <td
class="quintile-value summary-meanAge ui-corner-tr"></td
>
294 <td
class="quintile-value summary-sexRatio"></td
>
297 <td
>Age Dependency Ratio
:</td
>
298 <td
class="quintile-value summary-ageDependencyRatio"></td
>
301 <td
>Population
, Total
:</td
>
302 <td
class="quintile-value summary-populationTotal"></td
>
305 <td
>Population
, Male
:</td
>
306 <td
class="quintile-value summary-populationMale"></td
>
309 <td
class="ui-corner-bl">Population
, Female
:</td
>
310 <td
class="quintile-value summary-populationFemale ui-corner-br"></td
>
314 <table
class="highlighted-stats-table">
320 <tr
class="tooltip-header">
321 <td
class="tooltip-header ui-corner-top" colspan
="2">Highlighted Age
: <span
class="tooltip-item tooltipAge"> 
;</span
></td
>
324 <td
>Population
, Male
: </td
>
325 <td
class="quintile-value"><span
class="tooltip-item tooltipMale"> 
;</span
></td
>
328 <td
>Population
, Female
: </td
>
329 <td
class="quintile-value"><span
class="tooltip-item tooltipFemale"> 
;</span
></td
>
332 <td
class="ui-corner-bl">Sex Ratio
: </td
>
333 <td
class="quintile-value ui-corner-br"><span
class="tooltip-item tooltipRatio"> 
;</span
></td
>
346 <script
class="code" type
="text/javascript">
347 $
(document
).ready(function(){
349 // if browser supports canvas, show additional toolbar icons
350 if (!$
.jqplot
.use_excanvas
) {
351 $
('div.quintile-toolbar').append('<div class="ui-icon ui-icon-image"></div><div class="ui-icon ui-icon-print"></div>');
354 // for this demo, all data is same for each quintile.
355 // could do something like this to get the index of the quintile.
356 // <!-- var quintileIndex = parseInt(< ? php echo $_GET["qidx"]; ? >); -->
369 contentType
: "application/json",
370 success
: function (retdata
) {
371 // array of arrays of data for each quintile
372 // each quintile array has data for following:
379 error
: function (xhr
) { console
.log("ERROR: ", xhr
.statusText
) }
383 // the "x" values from the data will go into the ticks array.
384 // ticks should be strings for this case where we have values like "75+"
385 var ticks
= jsondata
[4];
387 $
('td.summary-meanAge').each(function(index
) {
388 $
(this
).html($
.jqplot
.sprintf('%5.2f', jsondata
[0][3]));
391 $
('td.summary-sexRatio').each(function(index
) {
392 $
(this
).html($
.jqplot
.sprintf('%5.2f', jsondata
[3][0]));
395 $
('td.summary-ageDependencyRatio').each(function(index
) {
396 $
(this
).html($
.jqplot
.sprintf('%5.2f', jsondata
[0][6]));
399 $
('td.summary-populationTotal').each(function(index
) {
400 $
(this
).html($
.jqplot
.sprintf("%'d", jsondata
[0][0]));
403 $
('td.summary-populationMale').each(function(index
) {
404 $
(this
).html($
.jqplot
.sprintf("%'d", jsondata
[0][1]));
407 $
('td.summary-populationFemale').each(function(index
) {
408 $
(this
).html($
.jqplot
.sprintf("%'d", jsondata
[0][2]));
411 // These two variables should be removed outside of the jqplot.com example environment.
412 $
.jqplot
._noToImageButton
= true;
413 $
.jqplot
._noCodeBlock
= true;
415 // Custom color arrays are set up for each series to get the look that is desired.
416 // Two color arrays are created for the default and optional color which the user can pick.
417 var greenColors
= ["#526D2C", "#77933C", "#C57225", "#C57225"];
418 var blueColors
= ["#3F7492", "#4F9AB8", "#C57225", "#C57225"];
420 // To accomodate changing y axis, need to keep track of plot options.
421 // changing axes will require recreating the plot, so need to keep
422 // track of state changes.
424 // We set up a customized title which acts as labels for the left and right sides of the pyramid.
426 text
: '<span style="margin-left:25%;">Male</span><span style="margin-left:33%;">Female</span>',
429 // by default, the series will use the green color scheme.
430 seriesColors
: greenColors
,
435 background
: "#ffffff",
437 // plotBands is an option of the pyramidGridRenderer.
438 // it will put banding at starting at a specified value
439 // along the y axis with an adjustable interval.
443 color
: 'rgb(245, 235, 215)'
448 // This makes the effective starting value of the axes 0 instead of 1.
449 // For display, the y axis will use the ticks we supplied.
452 renderer
: $
.jqplot
.PyramidRenderer
,
461 // We have 4 series, the left and right pyramid bars and
462 // the left and rigt overlay lines.
464 // For pyramid plots, the default side is right.
465 // We want to override here to put first set of bars
470 synchronizeHighlight
: 1
476 synchronizeHighlight
: 0
502 // Set up all the y axes, since users are allowed to switch between them.
503 // The only axis that will show is the one that the series are "attached" to.
504 // We need the appropriate options for the others for when the user switches.
508 formatter
: $
.jqplot
.PercentTickFormatter
,
509 formatString
: '%.1f%%'
514 // Use canvas label renderer to get rotated labels.
515 labelRenderer
: $
.jqplot
.CanvasAxisLabelRenderer
,
516 // include empty tick options, they will be used
517 // as users set options with plot controls.
519 showMinorTicks
: false,
523 tickSpacingFactor
: 15,
529 // include empty tick options, they will be used
530 // as users set options with plot controls.
532 showMinorTicks
: false,
536 tickSpacingFactor
: 15,
542 // Use canvas label renderer to get rotated labels.
543 labelRenderer
: $
.jqplot
.CanvasAxisLabelRenderer
,
544 // include empty tick options, they will be used
545 // as users set options with plot controls.
547 showMinorTicks
: false,
551 tickSpacingFactor
: 15,
558 // resize the chart container to fill the space
559 $
('#agesChart').height($
('div.chart-cell').height()*0.96);
560 $
('#agesChart').width($
('div.chart-cell').width()*0.97);
562 // $('#agesChart').jqplot([jsondata[1], jsondata[2]], plotOptions);
563 $
.jqplot
.config
.addDomReference
= true;
564 var plot1
= $
.jqplot('agesChart', [jsondata
[1], jsondata
[2]], plotOptions
);
566 $
(window
).resize (function(event
, ui
) {
567 // pass in resetAxes: true option to get rid of old ticks and axis properties
568 // which should be recomputed based on new plot size.
569 $
('#agesChart').height($
('div.chart-cell').height()*0.96);
570 $
('#agesChart').width($
('div.chart-cell').width()*0.97);
571 plot1
.replot( { resetAxes
: true } );
574 // initialize form elements
575 // set these before attaching event handlers.
577 $
("input[type=checkbox][name=gridsVertical]").attr("checked", false);
578 $
("input[type=checkbox][name=gridsHorizontal]").attr("checked", false);
579 $
("input[type=checkbox][name=showMinorTicks]").attr("checked", true);
580 $
("input[type=checkbox][name=plotBands]").attr("checked", true);
581 $
("input[type=checkbox][name=showContour]").attr("checked", true);
582 $
("input[type=checkbox][name=barPadding]").attr("checked", true);
583 $
("select[name=axisPosition]").val("both");
586 // The followng functions use verbose css selectors to make
587 // it clear exactly which elements they are binging to/operating on
590 $
("select[name=axisPosition]").change(function(){
591 // this refers to the html element we are binding to.
592 // $(this) is jQuery object on that element.
594 var opts
= {series
:[{}, {}, {}, {}]};
596 switch ($
(this
).val()) {
598 opts
.series
[0].yaxis
= "yaxis";
599 opts
.series
[1].yaxis
= "y2axis";
600 opts
.series
[2].yaxis
= "yaxis";
601 opts
.series
[3].yaxis
= "y2axis";
604 opts
.series
[0].yaxis
= "yaxis";
605 opts
.series
[1].yaxis
= "yaxis";
606 opts
.series
[2].yaxis
= "yaxis";
607 opts
.series
[3].yaxis
= "yaxis";
610 opts
.series
[0].yaxis
= "y2axis";
611 opts
.series
[1].yaxis
= "y2axis";
612 opts
.series
[2].yaxis
= "y2axis";
613 opts
.series
[3].yaxis
= "y2axis";
616 opts
.series
[0].yaxis
= "yMidAxis";
617 opts
.series
[1].yaxis
= "yMidAxis";
618 opts
.series
[2].yaxis
= "yMidAxis";
619 opts
.series
[3].yaxis
= "yMidAxis";
629 // bind to the data highlighting event to make custom tooltip:
630 $
(".jqplot-target").each(function(index
){
631 $
(this
).bind("jqplotDataHighlight", function(evt
, seriesIndex
, pointIndex
, data
) {
632 // Here, assume first series is male poulation and second series is female population.
633 // Adjust series indices as appropriate.
634 var plot
= $
(this
).data('jqplot');
635 var malePopulation
= Math
.abs(plot
.series
[0].data
[pointIndex
][1]) * jsondata
[0][1];
636 var femalePopulation
= Math
.abs(plot
.series
[1].data
[pointIndex
][1]) * jsondata
[0][2];
637 var malePopulation
= jsondata
[1][pointIndex
] * jsondata
[0][1];
638 var femalePopulation
= jsondata
[2][pointIndex
] * jsondata
[0][2];
639 // var ratio = femalePopulation / malePopulation * 100;
640 var ratio
= jsondata
[3][pointIndex
];
642 $
('.tooltipMale').stop(true, true).fadeIn(350).html($
.jqplot
.sprintf("%'d", malePopulation
));
643 $
('.tooltipFemale').stop(true, true).fadeIn(350).html($
.jqplot
.sprintf("%'d", femalePopulation
));
644 $
('.tooltipRatio').stop(true, true).fadeIn(350).html($
.jqplot
.sprintf('%5.2f', ratio
));
646 // Since we don't know which axis is rendererd and acive with out a little extra work,
647 // just use the supplied ticks array to get the age label.
648 $
('.tooltipAge').stop(true, true).fadeIn(350).html(ticks
[pointIndex
]);
652 // bind to the data highlighting event to make custom tooltip:
653 $
(".jqplot-target").each(function() {
654 $
(this
).bind("jqplotDataUnhighlight", function(evt
, seriesIndex
, pointIndex
, data
) {
655 // clear out all the tooltips.
656 $
(".tooltip-item").fadeOut(250);
660 $
('.ui-icon-print').click(function(){
661 $
(this
).parent().next().print();
665 $
("input[type=checkbox][name=gridsVertical]").change(function(){
666 // this refers to the html element we are binding to.
667 // $(this) is jQuery object on that element.
668 var opts
= {axes
: {xaxis
: {tickOptions
: {showGridline
: this
.checked
}}}};
673 $
("input[type=checkbox][name=gridsHorizontal]").change(function(){
674 // this refers to the html element we are binding to.
675 // $(this) is jQuery object on that element.
679 tickOptions
: {showGridline
: this
.checked
}
682 tickOptions
: {showGridline
: this
.checked
}
685 tickOptions
: {showGridline
: this
.checked
}
692 $
("input[type=checkbox][name=plotBands]").change(function(){
693 // this refers to the html element we are binding to.
694 // $(this) is jQuery object on that element.
695 var opts
= {grid
:{ rendererOptions
: {plotBands
: { show
: this
.checked
}}}};
702 // initialize form elements on reload.
703 // figure out what overlay line would be.
704 // have to adjust ticks to do show minor.
705 // make like kcp_pyramid.php
707 $
("input[type=checkbox][name=showMinorTicks]").change(function(){
708 // this refers to the html element we are binding to.
709 // $(this) is jQuery object on that element.
713 showMinorTicks
: !this
.checked
716 showMinorTicks
: !this
.checked
719 showMinorTicks
: !this
.checked
726 $
("input[type=checkbox][name=barPadding]").change(function(){
727 // this refers to the html element we are binding to.
728 // $(this) is jQuery object on that element.
730 var val
= parseFloat($
(this
).val());
752 $
('.ui-icon-image').each(function() {
753 $
(this
).bind('click', function(evt
) {
754 var chart
= $
(this
).closest('div.quintile-outer-container').find('div.jqplot-target');
755 var imgelem
= chart
.jqplotToImageElem();
756 var div
= $
('div.overlay-chart-container-content');
759 $
('div.overlay-shadow').fadeIn(600);
760 div
.parent().fadeIn(1000);
765 $
('div.overlay-chart-container-header div.ui-icon-closethick').click(function(){
766 var div
= $
('div.overlay-chart-container-content');
767 div
.parent().fadeOut(600);
768 $
('div.overlay-shadow').fadeOut(1000);
771 function applyColors () {
772 var opts
= {series
:[{}, {}], grid
:{rendererOptions
:{plotBands
:{}}}};
773 opts
.series
[0].color
= $
('#colorMale').data('colorpicker').color
.toCSS();
774 opts
.series
[1].color
= $
('#colorFemale').data('colorpicker').color
.toCSS();
775 opts
.grid
.background
= $
('#colorBackground').data('colorpicker').color
.toCSS();
776 opts
.grid
.rendererOptions
.plotBands
.color
= $
('#colorPlotBands').data('colorpicker').color
.toCSS();
782 // $('#colorMale').val(plot1.series[0].color);
784 $
('#colorMale').colorpicker({
788 buttonColorize
: true,
789 buttonImageOnly
: true,
791 color
: plot1
.series
[0].color
,
796 $
('#colorFemale').colorpicker({
800 buttonColorize
: true,
801 buttonImageOnly
: true,
803 color
: plot1
.series
[1].color
,
808 $
('#colorBackground').colorpicker({
812 buttonColorize
: true,
813 buttonImageOnly
: true,
815 color
: plot1
.grid
.background
,
820 $
('#colorPlotBands').colorpicker({
824 buttonColorize
: true,
825 buttonImageOnly
: true,
827 color
: plot1
.grid
.plotBands
.color
,
836 <script
class="include" type
="text/javascript" src
="../jquery.jqplot.js"></script
>
837 <script type
="text/javascript" src
="syntaxhighlighter/scripts/shCore.min.js"></script
>
838 <script type
="text/javascript" src
="syntaxhighlighter/scripts/shBrushJScript.min.js"></script
>
839 <script type
="text/javascript" src
="syntaxhighlighter/scripts/shBrushXml.min.js"></script
>
842 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.categoryAxisRenderer.js"></script
>
844 <!-- 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
. -->
845 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.pyramidAxisRenderer.js"></script
>
846 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.pyramidGridRenderer.js"></script
>
848 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.pyramidRenderer.js"></script
>
849 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.canvasTextRenderer.js"></script
>
850 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.canvasAxisLabelRenderer.js"></script
>
851 <script
class="include" type
="text/javascript" src
="../plugins/jqplot.json2.js"></script
>
852 <script
class="include" type
="text/javascript" src
="jquery-ui/js/jquery-ui.min.js"></script
>
853 <script
class="include" type
="text/javascript" src
="kcp.print.js"></script
>
855 <script src
="colorpicker/jquery.colorpicker.js"></script
>
857 <script type
="text/javascript" src
="example.js"></script
>