| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title>jQuery tablesorter 2.0 - Chart Widget</title> |
| 6 |
|
| 7 |
|
| 8 |
<script src="js/jquery-latest.min.js"></script> |
| 9 |
<script src="js/jquery-ui.min.js"></script> |
| 10 |
|
| 11 |
|
| 12 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css"> |
| 13 |
<link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css"> |
| 14 |
<link rel="stylesheet" href="css/jq.css"> |
| 15 |
<link rel="stylesheet" href="css/prettify.css"> |
| 16 |
<script src="js/prettify.js"></script> |
| 17 |
<script src="js/docs.js"></script> |
| 18 |
<link rel="stylesheet" href="css/bootstrap-v3.min.css"> |
| 19 |
<script src="js/bootstrap.min.js"></script> |
| 20 |
|
| 21 |
|
| 22 |
<script src="https://www.google.com/jsapi"></script> |
| 23 |
|
| 24 |
|
| 25 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 26 |
<script src="../js/jquery.tablesorter.js"></script> |
| 27 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 28 |
|
| 29 |
<script src="../js/widgets/widget-cssStickyHeaders.js"></script> |
| 30 |
<script src="../js/widgets/widget-columnSelector.js"></script> |
| 31 |
<script src="../js/widgets/widget-pager.js"></script> |
| 32 |
<script src="../js/widgets/widget-chart.js"></script> |
| 33 |
|
| 34 |
<style> |
| 35 |
h1 { font-size: 28px; } |
| 36 |
/* override jQuery UI overriding Bootstrap */ |
| 37 |
.accordion .ui-widget-content a { |
| 38 |
color: #337ab7; |
| 39 |
} |
| 40 |
/* .spacer in docs css is set to height:800px for stickyHeader demo */ |
| 41 |
#pager .spacer { height: auto; } |
| 42 |
.wrapper { padding: 5px; } |
| 43 |
</style> |
| 44 |
|
| 45 |
<style id="css">#pager div { |
| 46 |
display: inline-block; |
| 47 |
} |
| 48 |
|
| 49 |
#pager-container .spacer { |
| 50 |
padding: 0 5px; |
| 51 |
} |
| 52 |
|
| 53 |
#pager-container, |
| 54 |
#chart-container { |
| 55 |
text-align: center; |
| 56 |
} |
| 57 |
|
| 58 |
#chart-container > div { |
| 59 |
display: inline-block; |
| 60 |
} |
| 61 |
|
| 62 |
#chartbar { |
| 63 |
text-align: center; |
| 64 |
} |
| 65 |
|
| 66 |
#chartbar i.clickable { |
| 67 |
padding: 0 5px; |
| 68 |
} |
| 69 |
|
| 70 |
i.clickable { |
| 71 |
cursor: pointer; |
| 72 |
color: #999; |
| 73 |
} |
| 74 |
|
| 75 |
i.clickable.disabled, |
| 76 |
i.clickable.disabled:hover { |
| 77 |
cursor: not-allowed; |
| 78 |
color: #ccc; |
| 79 |
} |
| 80 |
|
| 81 |
i.active.clickable, |
| 82 |
i.clickable:hover { |
| 83 |
color: #000; |
| 84 |
} |
| 85 |
|
| 86 |
/*** custom css only popup ***/ |
| 87 |
.columnSelector, .hidden, #chart-container { |
| 88 |
display: none; |
| 89 |
} |
| 90 |
#colSelect:checked + label { |
| 91 |
background: #5797d7; |
| 92 |
border-color: #555; |
| 93 |
} |
| 94 |
#colSelect:checked ~ #columnSelector { |
| 95 |
display: block; |
| 96 |
} |
| 97 |
#chartSelect:checked + label { |
| 98 |
background: #5797d7; |
| 99 |
border-color: #555; |
| 100 |
} |
| 101 |
.columnSelector { |
| 102 |
width: 120px; |
| 103 |
position: absolute; |
| 104 |
margin-top: 5px; |
| 105 |
padding: 10px; |
| 106 |
background: #fff; |
| 107 |
border: #ccc 1px solid; |
| 108 |
border-radius: 5px; |
| 109 |
} |
| 110 |
.columnSelector label { |
| 111 |
display: block; |
| 112 |
text-align: left; |
| 113 |
} |
| 114 |
.columnSelector label:nth-child(1) { |
| 115 |
border-bottom: #99bfe6 solid 1px; |
| 116 |
margin-bottom: 5px; |
| 117 |
} |
| 118 |
.columnSelector input { |
| 119 |
margin-right: 5px; |
| 120 |
} |
| 121 |
.columnSelector .disabled { |
| 122 |
color: #ddd; |
| 123 |
}</style> |
| 124 |
</head> |
| 125 |
<body> |
| 126 |
<div id="banner"> |
| 127 |
<h1>table<em>sorter</em></h1> |
| 128 |
<h2>Chart Widget (beta)</h2> |
| 129 |
<h3>Flexible client-side table sorting</h3> |
| 130 |
<a href="index.html">Back to documentation</a> |
| 131 |
</div> |
| 132 |
<div id="main"> |
| 133 |
<p></p> |
| 134 |
<br> |
| 135 |
<div id="root" class="accordion"> |
| 136 |
|
| 137 |
<h3 id="notes"><a href="#">Notes</a></h3> |
| 138 |
<div> |
| 139 |
<ul> |
| 140 |
<li>This widget will <strong>only work</strong> in tablesorter version 2.16+ and jQuery version 1.7+.</li> |
| 141 |
<li>It only provides data for charts.</li> |
| 142 |
<li>Currently it provides data for the following chart libraries: |
| 143 |
<ul> |
| 144 |
<li><a href="https://developers.google.com/chart/">Google charts</a></li> |
| 145 |
<li><a href="http://www.highcharts.com/">Highcharts</a></li> |
| 146 |
<li><a href="http://www.fusioncharts.com/">FusionCharts</a></li> |
| 147 |
</ul> |
| 148 |
More details are available within the named "Setup" sections below. |
| 149 |
</li> |
| 150 |
</ul> |
| 151 |
</div> |
| 152 |
|
| 153 |
<h3 id="options"><a href="#">Options</a></h3> |
| 154 |
<div> |
| 155 |
<div> |
| 156 |
<span class="label label-info">TIP!</span> Click on the link in the function column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location. |
| 157 |
</div> |
| 158 |
|
| 159 |
<table class="options tablesorter-blue"> |
| 160 |
<thead> |
| 161 |
<tr><th class="option">Option</th><th class="defaults">Default</th><th class="sorter-false">Description</th></tr> |
| 162 |
</thead> |
| 163 |
<tbody> |
| 164 |
|
| 165 |
<tr id="chart-inc-rows"> |
| 166 |
<td><a href="#" class="permalink">chart_incRows</a></td> |
| 167 |
<td>'filtered' <span class="results">*</span></td> |
| 168 |
<td>Select which rows to include in the chart. |
| 169 |
<div class="collapsible"> |
| 170 |
<p></p> |
| 171 |
This option allows you to select which rows to include in the chart data: |
| 172 |
<ul> |
| 173 |
<li><code>'a'</code> - Include <em>all</em> rows, even if the table has been filtered or partially hidden by the pager.</li> |
| 174 |
<li><code>'v'</code> - Include only <em>visible</em> rows, whether they are hidden by the pager or filter.</li> |
| 175 |
<li><code>'f'</code> - Include only <em>filtered</em> rows, even if the pager is only showing a select few rows.</li> |
| 176 |
</ul> |
| 177 |
<span class="results">*</span> Only the first letter is required, but the option will accept the full word (e.g. 'filtered' instead of 'f') |
| 178 |
</div> |
| 179 |
</td> |
| 180 |
</tr> |
| 181 |
|
| 182 |
<tr id="chart-use-selector"> |
| 183 |
<td><a href="#" class="permalink">chart_useSelector</a></td> |
| 184 |
<td>false</td> |
| 185 |
<td>Use the columnSelector widget in place of the <code>chart_ignoreColumns</code> option. |
| 186 |
<div class="collapsible"> |
| 187 |
<p></p> |
| 188 |
Set this option to <code>true</code> if using the columnSelector widget. |
| 189 |
<p></p> |
| 190 |
If using a custom column selector, then set this option to <code>false</code> and use the custom selector to update the <code>chart_ignoreColumns</code> option dynamically. |
| 191 |
</div> |
| 192 |
</td> |
| 193 |
</tr> |
| 194 |
|
| 195 |
<tr id="chart-ignore-columns"> |
| 196 |
<td><a href="#" class="permalink">chart_ignoreColumns</a></td> |
| 197 |
<td>[ ]</td> |
| 198 |
<td>Array of zero-based column indexes of columns to ignore. |
| 199 |
<div class="collapsible"> |
| 200 |
<p></p> |
| 201 |
This option is used when the <code>chart_useSelector</code> option is <code>false</code> or if the columnSelector is set to "auto" mode. |
| 202 |
<p></p> |
| 203 |
Update this option dynamically, if using a custom method to hide/indicate which columns are to be ignored when gathering data for the chart. |
| 204 |
</div> |
| 205 |
</td> |
| 206 |
</tr> |
| 207 |
|
| 208 |
<tr id="chart-parsed"> |
| 209 |
<td><a href="#" class="permalink">chart_parsed</a></td> |
| 210 |
<td>[ ]</td> |
| 211 |
<td>Array of zero-based column indexes of columns that must used parsed data for charting. |
| 212 |
<div class="collapsible"> |
| 213 |
<p></p> |
| 214 |
Parsed data is gathered from the table cache, which is parsed the designated parser for that column. |
| 215 |
<p></p> |
| 216 |
This option can be updated dynamically. |
| 217 |
</div> |
| 218 |
</td> |
| 219 |
</tr> |
| 220 |
|
| 221 |
<tr id="chart-layout"> |
| 222 |
<td><a href="#" class="permalink">chart_layout</a></td> |
| 223 |
<td>{ 0: 'string' }</td> |
| 224 |
<td>Object containing the format needed by the chart for each column. |
| 225 |
<div class="collapsible"> |
| 226 |
<p></p> |
| 227 |
By default, all columns will have their values converted to numbers. Prior to sending the value to tablesorter's <a href="index.html#function-formatfloat"><code>formatFloat</code></a> function, the value will have all non-digit characters stripped out. |
| 228 |
<p></p> |
| 229 |
Set the zero-based column index of the desired column to <code>'s'</code> (only the first letter is needed) to pass the cell value to the chart as a string. |
| 230 |
<p></p> |
| 231 |
This option can be updated dynamically. |
| 232 |
</div> |
| 233 |
</td> |
| 234 |
</tr> |
| 235 |
|
| 236 |
<tr id="chart-label-col"> |
| 237 |
<td><a href="#" class="permalink">chart_labelCol</a></td> |
| 238 |
<td>0</td> |
| 239 |
<td>Set a zero-based column index for the column to be used as a chart label. |
| 240 |
<div class="collapsible"> |
| 241 |
<p></p> |
| 242 |
The chart label (independent variable) is usually the first array value in each nested array (at least for Google charts). In this demo, it is the Year. |
| 243 |
</div> |
| 244 |
</td> |
| 245 |
</tr> |
| 246 |
|
| 247 |
<tr id="chart-sort"> |
| 248 |
<td><a href="#" class="permalink">chart_sort</a></td> |
| 249 |
<td>[ [ 0,0 ] ]</td> |
| 250 |
<td>Sort a specific column of data using the same format as tablesorter's <code>sortList</code> option; but for a single column. |
| 251 |
<div class="collapsible"> |
| 252 |
<p></p> |
| 253 |
Set this value to be an array contained within an array using the following format: <code>[[ column, direction ]]</code> |
| 254 |
<p></p> |
| 255 |
<span class="label label-info">* Note *</span> It would be best to sort the same column as the <code>chart_labelCol</code> to keep the axis ordered properly; but that is up to you ;) |
| 256 |
<p></p> |
| 257 |
<ul> |
| 258 |
<li><code>column</code> - zero-based index of the column to sort.</li> |
| 259 |
<li><code>direction</code> - sort direction; <code>0</code> indicates an ascending sort, and <code>1</code> indicates a descending sort is to be used.</li> |
| 260 |
</ul> |
| 261 |
<span class="label warning">* Note *</span> Anything other than <code>1</code> as the sort direction will set an ascending sort. |
| 262 |
</div> |
| 263 |
</td> |
| 264 |
</tr> |
| 265 |
|
| 266 |
<tr id="chart-event"> |
| 267 |
<td><a href="#" class="permalink">chart_event</a></td> |
| 268 |
<td>'chartData'</td> |
| 269 |
<td>The chart data will be updated when this event is triggered on the table. |
| 270 |
<div class="collapsible"> |
| 271 |
<p></p> |
| 272 |
Trigger a chart data update, then get the data as follows: |
| 273 |
<pre class="prettyprint lang-js">var $table = $('table').trigger('chartData'), |
| 274 |
data = $table[0].config.chart.data; |
| 275 |
chartData( data ); // custom function to chart the data</pre> |
| 276 |
</div> |
| 277 |
</td> |
| 278 |
</tr> |
| 279 |
|
| 280 |
</tbody> |
| 281 |
</table> |
| 282 |
</div> |
| 283 |
|
| 284 |
<h3 id="google"><a href="#">Setup - Google Charts</a></h3> |
| 285 |
<div> |
| 286 |
The data used by Google charts is an array of arrays in this format: |
| 287 |
<pre class="prettyprint lang-js">[ |
| 288 |
[ "Year", "Sales", "Expenses" ], |
| 289 |
[ "2004", 1000, 400 ], |
| 290 |
[ "2005", 1170, 460 ], |
| 291 |
[ "2006", 660, 1120 ], |
| 292 |
[ "2007", 1030, 540 ] |
| 293 |
]</pre> |
| 294 |
Access the data as follows: |
| 295 |
<pre class="prettyprint lang-js">var $table = $('table').trigger('chartData'), |
| 296 |
options = { /* set up options here */ }, |
| 297 |
rawdata = $table[0].config.chart.data, |
| 298 |
data = google.visualization.arrayToDataTable( rawdata ), |
| 299 |
// bar chart example |
| 300 |
chart = new google.visualization.BarChart( $('#chart')[0] ); |
| 301 |
chart.draw(data, options); |
| 302 |
</pre> |
| 303 |
</div> |
| 304 |
|
| 305 |
<h3 id="highcharts"><a href="#">Setup - Highcharts</a></h3> |
| 306 |
<div> |
| 307 |
The data used by Highcharts is an array of objects in this format: |
| 308 |
<pre class="prettyprint lang-js">// categories |
| 309 |
[ '2004', '2005', '2006', '2007' ] |
| 310 |
|
| 311 |
// series |
| 312 |
[{ |
| 313 |
name: 'Sales', |
| 314 |
data: [ 1000, 1170, 660, 1030 ] |
| 315 |
}, { |
| 316 |
name: 'Expenses', |
| 317 |
data: [ 400, 460, 1120, 540 ] |
| 318 |
}]</pre> |
| 319 |
Access the data as follows: |
| 320 |
<pre class="prettyprint lang-js">var $table = $('table').trigger('chartData'); |
| 321 |
|
| 322 |
$('#chart').highcharts({ |
| 323 |
chart: { type: 'column' }, |
| 324 |
xAxis: { categories: $table[0].config.chart.categories }, |
| 325 |
series: $table[0].config.chart.series |
| 326 |
}); |
| 327 |
</pre> |
| 328 |
</div> |
| 329 |
|
| 330 |
<h3 id="fusioncharts"><a href="#">Setup - FusionCharts</a></h3> |
| 331 |
<div> |
| 332 |
The data used by FusionCharts is an array of objects in this format: |
| 333 |
<pre class="prettyprint lang-js">// category |
| 334 |
[ |
| 335 |
{"label": "2004"}, |
| 336 |
{"label": "2005"}, |
| 337 |
{"label": "2006"}, |
| 338 |
{"label": "2007"} |
| 339 |
] |
| 340 |
// dataset |
| 341 |
[{ |
| 342 |
"seriesname": "Sales", |
| 343 |
"data": [ |
| 344 |
{"value": "1000"}, |
| 345 |
{"value": "1170"}, |
| 346 |
{"value": "660"}, |
| 347 |
{"value": "1030"} |
| 348 |
] |
| 349 |
},{ |
| 350 |
"seriesname": "Expenses", |
| 351 |
"data": [ |
| 352 |
{"value": "400"}, |
| 353 |
{"value": "600"}, |
| 354 |
{"value": "1120"}, |
| 355 |
{"value": "540"} |
| 356 |
] |
| 357 |
}]</pre> |
| 358 |
Access the data as follows: |
| 359 |
<pre class="prettyprint lang-js">var $table = $('table'); |
| 360 |
$table.trigger('chartData'); |
| 361 |
|
| 362 |
FusionCharts.ready(function () { |
| 363 |
var analysisChart = new FusionCharts({ |
| 364 |
dataFormat: 'json', |
| 365 |
dataSource: { |
| 366 |
"chart": { |
| 367 |
// ... |
| 368 |
}, |
| 369 |
"categories": [{ |
| 370 |
"category": $table[0].config.chart.category |
| 371 |
}], |
| 372 |
"dataset": $table[0].config.chart.dataset, |
| 373 |
}, |
| 374 |
// other options |
| 375 |
}).render(); |
| 376 |
});</pre> |
| 377 |
</div> |
| 378 |
|
| 379 |
</div> |
| 380 |
<p></p> |
| 381 |
|
| 382 |
<h1>Google Charts Demo</h1> |
| 383 |
<div id="demo"><div id="chart-container"> |
| 384 |
<div id="chart"></div> |
| 385 |
<p></p> |
| 386 |
<div id="chartbar"> |
| 387 |
<i class="fa fa-cube active clickable toolti" title="3D Pie Chart" data-toggle="tooltip" data-placement="top"></i> |
| 388 |
<i class="fa fa-pie-chart clickable" title="Pie Chart" data-toggle="tooltip" data-placement="top"></i> |
| 389 |
<i class="fa fa-line-chart clickable" title="Line Graph" data-toggle="tooltip" data-placement="top"></i> |
| 390 |
<i class="fa fa-area-chart clickable" title="Area Graph" data-toggle="tooltip" data-placement="top"></i> |
| 391 |
<i class="fa fa-bar-chart clickable" title="Vertical Bar Chart" data-toggle="tooltip" data-placement="top"></i> |
| 392 |
<i class="fa fa-tasks fa-rotate-90 clickable" title="Stacking Vertical Bar Chart" data-toggle="tooltip" data-placement="top"></i> |
| 393 |
<i class="fa fa-align-left clickable" title="Horizontal Bar Chart" data-toggle="tooltip" data-placement="top"></i> |
| 394 |
<i class="fa fa-tasks fa-rotate-180 clickable" title="Stacking Horizontal Bar Chart" data-toggle="tooltip" data-placement="top"></i> |
| 395 |
</div> |
| 396 |
<p></p> |
| 397 |
</div> |
| 398 |
|
| 399 |
|
| 400 |
<label for="colSelect" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="Toggle visible columns"> |
| 401 |
<input id="colSelect" type="checkbox" class="hidden"> |
| 402 |
<i class="fa fa-table"></i> Column |
| 403 |
<div id="columnSelector" class="columnSelector"></div> |
| 404 |
</label> |
| 405 |
|
| 406 |
<label for="chartSelect" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="Toggle chart visibility"> |
| 407 |
<input id="chartSelect" type="checkbox" class="hidden"> |
| 408 |
<i class="fa fa-pie-chart"></i> Chart |
| 409 |
</label> |
| 410 |
|
| 411 |
<span class="wrapper" data-toggle="tooltip" data-placement="top" title="Chart filtered, visible or all rows"> |
| 412 |
<div class="btn-group chart-filter-all" data-toggle="buttons"> |
| 413 |
<label class="btn btn-default btn-sm active"> |
| 414 |
<input type="radio" name="getrows" data-type="filter" checked="checked"> Filtered |
| 415 |
</label> |
| 416 |
<label class="btn btn-default btn-sm"> |
| 417 |
<input type="radio" name="getrows" data-type="visible"> Visible |
| 418 |
</label> |
| 419 |
<label class="btn btn-default btn-sm"> |
| 420 |
<input type="radio" name="getrows" data-type="all"> All |
| 421 |
</label> |
| 422 |
</div> |
| 423 |
</span> |
| 424 |
|
| 425 |
<table id="table" class="tablesorter"> |
| 426 |
<thead> |
| 427 |
<tr> |
| 428 |
<th>Year</th> |
| 429 |
<th>Sales</th> |
| 430 |
<th>Expenses</th> |
| 431 |
<th>Profit</th> |
| 432 |
</tr> |
| 433 |
</thead> |
| 434 |
<tbody> |
| 435 |
<tr><td>2000</td><td>$ 1,420</td><td>$ 470</td><td>$ 330</td></tr> |
| 436 |
<tr><td>2001</td><td>$ 1,070</td><td>$ 420</td><td>$ 190</td></tr> |
| 437 |
<tr><td>2002</td><td>$ 1,010</td><td>$ 270</td><td>$ 270</td></tr> |
| 438 |
<tr><td>2003</td><td>$ 1,220</td><td>$ 430</td><td>$ 460</td></tr> |
| 439 |
<tr><td>2004</td><td>$ 1,000</td><td>$ 400</td><td>$ 600</td></tr> |
| 440 |
<tr><td>2005</td><td>$ 1,170</td><td>$ 460</td><td>$ 710</td></tr> |
| 441 |
<tr><td>2006</td><td>$ 660</td><td>$ 1,120</td><td>($ 460)</td></tr> |
| 442 |
<tr><td>2007</td><td>$ 1,030</td><td>$ 540</td><td>$ 490</td></tr> |
| 443 |
<tr><td>2008</td><td>$ 2,150</td><td>$ 240</td><td>$ 410</td></tr> |
| 444 |
<tr><td>2009</td><td>$ 230</td><td>$ 660</td><td>$ 110</td></tr> |
| 445 |
<tr><td>2010</td><td>$ 1,110</td><td>$ 390</td><td>$ 520</td></tr> |
| 446 |
<tr><td>2011</td><td>$ 733</td><td>$ 110</td><td>$ 210</td></tr> |
| 447 |
<tr><td>2012</td><td>$ 870</td><td>$ 300</td><td>$ 190</td></tr> |
| 448 |
<tr><td>2013</td><td>$ 1,320</td><td>$ 490</td><td>$ 290</td></tr> |
| 449 |
<tr><td>2014</td><td>$ 950</td><td>$ 210</td><td>$ 140</td></tr> |
| 450 |
</tbody> |
| 451 |
</table> |
| 452 |
|
| 453 |
|
| 454 |
<div id="pager-container"> |
| 455 |
<div id="pager"> |
| 456 |
<form> |
| 457 |
<select class="pagesize" title="Select rows per page" data-toggle="tooltip" data-placement="left"> |
| 458 |
<option value="3">3</option> |
| 459 |
<option value="5">5</option> |
| 460 |
<option value="10">10</option> |
| 461 |
</select> |
| 462 |
<div class="spacer"><div class="separator"></div></div> |
| 463 |
<i class="fa fa-step-backward first clickable" title="First page"></i> |
| 464 |
<i class="fa fa-backward prev clickable" title="Previous page"></i> |
| 465 |
<div class="spacer"><div class="separator"></div></div> |
| 466 |
<span class="pagedisplay"></span> |
| 467 |
<div class="spacer"><div class="separator"></div></div> |
| 468 |
<i class="fa fa-forward next clickable" title="Next page"></i> |
| 469 |
<i class="fa fa-step-forward last clickable" title="Last page"></i> |
| 470 |
<div class="spacer"><div class="separator"></div></div> |
| 471 |
<select class="gotoPage" title="Select page" data-toggle="tooltip" data-placement="right"></select> |
| 472 |
</form> |
| 473 |
</div> |
| 474 |
</div> |
| 475 |
</div> |
| 476 |
|
| 477 |
<h1>Page Header</h1> |
| 478 |
<div> |
| 479 |
<pre class="prettyprint lang-html"><!-- Google charts --> |
| 480 |
<script src="//www.google.com/jsapi"></script> |
| 481 |
|
| 482 |
<!-- jQuery --> |
| 483 |
<script src="js/jquery-latest.min.js"></script> |
| 484 |
|
| 485 |
<!-- Demo stuff --> |
| 486 |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css"> |
| 487 |
<!-- buttons --> |
| 488 |
<link rel="stylesheet" href="css/bootstrap-v3.min.css"> |
| 489 |
<script src="js/bootstrap.min.js"></script> |
| 490 |
|
| 491 |
<!-- Tablesorter: required --> |
| 492 |
<link rel="stylesheet" href="../css/theme.blue.css"> |
| 493 |
<script src="../js/jquery.tablesorter.js"></script> |
| 494 |
<script src="../js/widgets/widget-chart.js"></script> |
| 495 |
|
| 496 |
<!-- Tablesorter: optional --> |
| 497 |
<script src="../js/jquery.tablesorter.widgets.js"></script> |
| 498 |
<script src="../js/widgets/widget-cssStickyHeaders.js"></script> |
| 499 |
<script src="../js/widgets/widget-columnSelector.js"></script> |
| 500 |
<script src="../js/widgets/widget-pager.js"></script></pre> |
| 501 |
</div> |
| 502 |
|
| 503 |
<h1>Javascript</h1> |
| 504 |
<div id="javascript"> |
| 505 |
<pre class="prettyprint lang-javascript"></pre> |
| 506 |
</div> |
| 507 |
|
| 508 |
<h1>CSS</h1> |
| 509 |
<div id="css"> |
| 510 |
<pre class="prettyprint lang-css"></pre> |
| 511 |
</div> |
| 512 |
|
| 513 |
<h1>HTML</h1> |
| 514 |
<div id="html"> |
| 515 |
<pre class="prettyprint lang-html"></pre> |
| 516 |
</div> |
| 517 |
|
| 518 |
</div> |
| 519 |
|
| 520 |
<script id="js">google.load("visualization", "1.1", { |
| 521 |
packages: ["bar", "corechart", "line"] |
| 522 |
}); |
| 523 |
|
| 524 |
$(function() { |
| 525 |
/* Initial settings */ |
| 526 |
var $table = $('#table'), |
| 527 |
$chart = $('#chart'), |
| 528 |
$bar = $('#chartbar'), |
| 529 |
$rowType = $('[name=getrows]'), |
| 530 |
$icons = $('#chart-container i'), |
| 531 |
initType = 'pie', // graph types ('pie', 'pie3D', 'line', 'area', 'vbar', 'vstack', 'hbar' or 'hstack') |
| 532 |
chartTitle = 'Company Performance', |
| 533 |
axisTitle = 'Year', |
| 534 |
width = 900, |
| 535 |
height = 500, |
| 536 |
// extra data processing |
| 537 |
processor = function(data) { |
| 538 |
// console.log(data); |
| 539 |
return data; |
| 540 |
}, |
| 541 |
|
| 542 |
// don't change anything below, unless you want to remove some types; modify styles and/or font-awesome icons |
| 543 |
types = { |
| 544 |
pie3D : { in3D: true, maxCol: 2, stack: false, type: 'pie', titleStyle: { color: '#333' }, icon: 'fa-cube' }, |
| 545 |
pie : { in3D: false, maxCol: 2, stack: false, type: 'pie', titleStyle: { color: '#333' }, icon: 'fa-pie-chart' }, |
| 546 |
line : { in3D: false, maxCol: 99,stack: false, type: 'line', titleStyle: { color: '#333' }, icon: 'fa-line-chart' }, |
| 547 |
area : { in3D: false, maxCol: 5, stack: false, type: 'area', titleStyle: { color: '#333' }, icon: 'fa-area-chart' }, |
| 548 |
vbar : { in3D: false, maxCol: 5, stack: false, type: 'vbar', titleStyle: { color: '#333' }, icon: 'fa-bar-chart' }, |
| 549 |
vstack : { in3D: false, maxCol: 5, stack: true, type: 'vbar', titleStyle: { color: '#333' }, icon: 'fa-tasks fa-rotate-90' }, |
| 550 |
hbar : { in3D: false, maxCol: 5, stack: false, type: 'hbar', titleStyle: { color: '#333' }, icon: 'fa-align-left' }, |
| 551 |
hstack : { in3D: false, maxCol: 5, stack: true, type: 'hbar', titleStyle: { color: '#333' }, icon: 'fa-tasks fa-rotate-180' } |
| 552 |
}, |
| 553 |
/* internal variables */ |
| 554 |
settings = { |
| 555 |
table : $table, |
| 556 |
chart : $chart[0], |
| 557 |
chartTitle : chartTitle, |
| 558 |
axisTitle : axisTitle, |
| 559 |
type : initType, |
| 560 |
processor : processor |
| 561 |
}, |
| 562 |
drawChart = function() { |
| 563 |
if (!$table[0].config) { return; } |
| 564 |
var options, chart, numofcols, data, |
| 565 |
s = settings, |
| 566 |
t = types[s.type], |
| 567 |
obj = s.chart, |
| 568 |
rawdata = $table[0].config.chart.data; |
| 569 |
if ( $.isFunction( s.processor ) ) { |
| 570 |
rawdata = s.processor( rawdata ); |
| 571 |
} |
| 572 |
if ( rawdata.length < 2 ) { |
| 573 |
return; |
| 574 |
} |
| 575 |
data = google.visualization.arrayToDataTable( rawdata ); |
| 576 |
|
| 577 |
numofcols = rawdata[1].length; |
| 578 |
if (numofcols > t.maxCol) { |
| 579 |
// default to line chart if too many columns selected |
| 580 |
t = types['line']; |
| 581 |
} |
| 582 |
|
| 583 |
options = { |
| 584 |
title: s.chartTitle, |
| 585 |
chart: { |
| 586 |
title: s.chartTitle |
| 587 |
}, |
| 588 |
hAxis: { |
| 589 |
title: s.axisTitle, |
| 590 |
titleTextStyle: t.titleStyle |
| 591 |
}, |
| 592 |
vAxis: {}, |
| 593 |
is3D: t.in3D, |
| 594 |
isStacked: t.stack, |
| 595 |
width: width, |
| 596 |
height: height |
| 597 |
}; |
| 598 |
|
| 599 |
if (t.type == 'vbar' && !t.stack) { |
| 600 |
chart = new google.charts.Bar(obj); |
| 601 |
} else if (t.type == 'vbar') { |
| 602 |
chart = new google.visualization.ColumnChart(obj); |
| 603 |
} else if (t.type == 'hbar') { |
| 604 |
options.hAxis = {}; |
| 605 |
options.vAxis = { |
| 606 |
title: s.axisTitle, |
| 607 |
titleTextStyle: t.titleStyle, |
| 608 |
minValue: 0 |
| 609 |
}; |
| 610 |
chart = new google.visualization.BarChart(obj); |
| 611 |
} else if (t.type == 'area') { |
| 612 |
chart = new google.visualization.AreaChart(obj); |
| 613 |
} else if (t.type == 'line') { |
| 614 |
chart = new google.charts.Line(obj); |
| 615 |
} else { |
| 616 |
chart = new google.visualization.PieChart(obj); |
| 617 |
} |
| 618 |
chart.draw(data, options); |
| 619 |
}; |
| 620 |
|
| 621 |
$('#chartSelect').change(function() { |
| 622 |
$('#chart-container').slideToggle( $(this).is(':checked') ); |
| 623 |
drawChart(); |
| 624 |
}); |
| 625 |
|
| 626 |
$icons.click(function(e) { |
| 627 |
if ( $(e.target).hasClass('disabled') ) { |
| 628 |
return true; |
| 629 |
} |
| 630 |
$icons.removeClass('active'); |
| 631 |
var $t = $(this).addClass('active'); |
| 632 |
$.each(types, function(i, v) { |
| 633 |
if ($t.hasClass(v.icon)) { |
| 634 |
settings.type = i; |
| 635 |
} |
| 636 |
}); |
| 637 |
drawChart(); |
| 638 |
}); |
| 639 |
|
| 640 |
$rowType.on('change', function() { |
| 641 |
$table[0].config.widgetOptions.chart_incRows = $rowType.filter(':checked').attr('data-type'); |
| 642 |
// update data, then draw new chart |
| 643 |
$table.trigger('chartData'); |
| 644 |
drawChart(); |
| 645 |
}); |
| 646 |
|
| 647 |
$table.on('columnUpdate pagerComplete', function(e) { |
| 648 |
var table = this, |
| 649 |
c = table.config, |
| 650 |
t = types['pie'], |
| 651 |
max = t && t.maxCol || 2; |
| 652 |
setTimeout(function() { |
| 653 |
if (table.hasInitialized) { |
| 654 |
$table.trigger('chartData'); |
| 655 |
drawChart(); |
| 656 |
// update chart icons |
| 657 |
if (typeof c.chart !== 'undefined') { |
| 658 |
var cols = c.chart.data[0].length; |
| 659 |
if (cols > max) { |
| 660 |
$bar.find('.fa-cube, .fa-pie-chart').addClass('disabled'); |
| 661 |
if ($bar.find('.fa-cube, .fa-pie-chart').hasClass('active')) { |
| 662 |
$bar.find('.fa-cube, .fa-pie-chart').removeClass('active'); |
| 663 |
$bar.find('.fa-line-chart').addClass('active'); |
| 664 |
} |
| 665 |
} else { |
| 666 |
$bar.find('.fa-cube, .fa-pie-chart').removeClass('disabled'); |
| 667 |
if (settings.type == 'pie') { |
| 668 |
$bar.find('.active').removeClass('active'); |
| 669 |
$bar.find( settings.in3D ? '.fa-cube' : '.fa-pie-chart' ).addClass('active'); |
| 670 |
} |
| 671 |
} |
| 672 |
} |
| 673 |
} |
| 674 |
}, 10); |
| 675 |
}); |
| 676 |
|
| 677 |
$table |
| 678 |
.tablesorter({ |
| 679 |
theme: 'blue', |
| 680 |
sortList: [[0, 0]], |
| 681 |
widgets: ['pager', 'zebra', 'filter', 'cssStickyHeaders', 'columnSelector', 'chart'], |
| 682 |
widgetOptions: { |
| 683 |
columnSelector_container: '#columnSelector', |
| 684 |
cssStickyHeaders_filteredToTop: false, |
| 685 |
pager_selectors: { container: '#pager' }, |
| 686 |
pager_output: 'Showing {startRow} to {endRow} of {filteredRows} results', |
| 687 |
pager_size: 5, |
| 688 |
chart_incRows: 'f', |
| 689 |
chart_useSelector: true |
| 690 |
} |
| 691 |
}); |
| 692 |
|
| 693 |
});</script> |
| 694 |
|
| 695 |
<script> |
| 696 |
$(function() { |
| 697 |
$('[data-toggle="tooltip"]').tooltip(); |
| 698 |
}); |
| 699 |
</script> |
| 700 |
|
| 701 |
</body> |
| 702 |
</html> |