You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * Multiple PivotGrid examples. Each PivotGrid shares a common Record and Store and simply presents
  17. * the data in a different way. For full details on using PivotGrid see the API documentation.
  18. */
  19. Ext.onReady(function() {
  20. var PersonRecord = Ext.data.Record.create([
  21. {name: 'eyeColor', type: 'string'},
  22. {name: 'birthDecade', type: 'string'},
  23. {name: 'handedness', type: 'string'},
  24. {name: 'gender', type: 'string'},
  25. {name: 'height', type: 'int'},
  26. {name: 'iq', type: 'int'}
  27. ]);
  28. var myStore = new Ext.data.Store({
  29. url: 'people.json',
  30. autoLoad: true,
  31. reader: new Ext.data.JsonReader({
  32. root: 'rows',
  33. idProperty: 'id'
  34. }, PersonRecord)
  35. });
  36. var averageHeight = new Ext.grid.PivotGrid({
  37. title : 'Average height',
  38. width : 600,
  39. height : 154,
  40. renderTo : 'avgHeight',
  41. store : myStore,
  42. aggregator: 'avg',
  43. measure : 'height',
  44. //turns a decimal number of feet into feet and inches
  45. renderer : function(value) {
  46. var feet = Math.floor(value),
  47. inches = Math.round((value - feet) * 12);
  48. return String.format("{0}' {1}\"", feet, inches);
  49. },
  50. leftAxis: [
  51. {
  52. width: 80,
  53. dataIndex: 'birthDecade'
  54. }
  55. ],
  56. topAxis: [
  57. {
  58. dataIndex: 'gender'
  59. },
  60. {
  61. dataIndex: 'handedness'
  62. }
  63. ]
  64. });
  65. var perDecade = new Ext.grid.PivotGrid({
  66. title : 'Number of people born per decade',
  67. width : 600,
  68. height : 91,
  69. renderTo : 'perDecade',
  70. store : myStore,
  71. aggregator: 'count',
  72. topAxis: [
  73. {
  74. width: 80,
  75. dataIndex: 'birthDecade'
  76. }
  77. ],
  78. leftAxis: [
  79. {
  80. dataIndex: 'gender'
  81. }
  82. ]
  83. });
  84. var maxIQ = new Ext.grid.PivotGrid({
  85. title : 'Max IQ per decade',
  86. width : 600,
  87. height : 91,
  88. renderTo : 'maxIQ',
  89. store : myStore,
  90. measure : 'iq',
  91. aggregator: 'max',
  92. topAxis: [
  93. {
  94. width: 80,
  95. dataIndex: 'birthDecade'
  96. },
  97. {
  98. dataIndex: 'handedness'
  99. }
  100. ]
  101. });
  102. });