3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
20 'Ext.layout.container.Column'
24 Ext.onReady(function(){
26 //use a renderer for values in the data view.
31 var bd = Ext.getBody(),
34 selectedStoreItem = false,
35 //performs the highlight of an item in the bar series
36 selectItem = function(storeItem) {
37 var name = storeItem.get('company'),
38 series = barChart.series.get(0),
41 series.highlight = true;
42 series.unHighlightItem();
43 series.cleanHighlights();
44 for (i = 0, items = series.items, l = items.length; i < l; i++) {
45 if (name == items[i].storeItem.get('company')) {
46 selectedStoreItem = items[i].storeItem;
47 series.highlightItem(items[i]);
51 series.highlight = false;
53 //updates a record modified via the form
54 updateRecord = function(rec) {
55 var name, series, i, l, items, json = [{
57 'Data': rec.get('price')
60 'Data': rec.get('revenue %')
63 'Data': rec.get('growth %')
66 'Data': rec.get('product %')
69 'Data': rec.get('market %')
74 createListeners = function() {
76 // buffer so we don't refire while the user is still typing
78 change: function(field, newValue, oldValue, listener) {
80 if (newValue > field.maxValue) {
81 field.setValue(field.maxValue);
83 form.updateRecord(rec);
91 // sample static data for the store
96 ['American Express Company'],
97 ['American International Group, Inc.'],
100 ['Caterpillar Inc.'],
102 ['E.I. du Pont de Nemours and Company'],
103 ['Exxon Mobil Corp'],
104 ['General Electric Company'],
105 ['General Motors Corporation'],
106 ['Hewlett-Packard Co'],
107 ['Honeywell Intl Inc'],
108 ['Intel Corporation'],
109 ['International Business Machines'],
110 ['Johnson & Johnson'],
111 ['JP Morgan & Chase & Co'],
112 ['McDonald\'s Corporation'],
113 ['Merck & Co., Inc.'],
114 ['Microsoft Corporation'],
116 ['The Coca-Cola Company'],
117 ['The Home Depot, Inc.'],
118 ['The Procter & Gamble Company'],
119 ['United Technologies Corporation'],
120 ['Verizon Communications'],
121 ['Wal-Mart Stores, Inc.']
124 for (var i = 0, l = myData.length, rand = Math.random; i < l; i++) {
125 var data = myData[i];
126 data[1] = ((rand() * 10000) >> 0) / 100;
127 data[2] = ((rand() * 10000) >> 0) / 100;
128 data[3] = ((rand() * 10000) >> 0) / 100;
129 data[4] = ((rand() * 10000) >> 0) / 100;
130 data[5] = ((rand() * 10000) >> 0) / 100;
133 //create data store to be shared among the grid and bar series.
134 var ds = Ext.create('Ext.data.ArrayStore', {
137 {name: 'price', type: 'float'},
138 {name: 'revenue %', type: 'float'},
139 {name: 'growth %', type: 'float'},
140 {name: 'product %', type: 'float'},
141 {name: 'market %', type: 'float'}
146 //create radar dataset model.
147 var chs = Ext.create('Ext.data.JsonStore', {
148 fields: ['Name', 'Data'],
168 //Radar chart will render information for a selected company in the
169 //list. Selection can also be done via clicking on the bars in the series.
170 var radarChart = Ext.create('Ext.chart.Chart', {
193 fill: 'rgb(194,214,240)',
200 //create a grid that will list the dataset items.
201 var gridPanel = Ext.create('Ext.grid.Panel', {
205 title:'Company Data',
228 dataIndex: 'revenue %',
236 dataIndex: 'growth %',
244 dataIndex: 'product %',
252 dataIndex: 'market %',
258 selectionchange: function(model, records) {
259 var json, name, i, l, items, series, fields;
263 form = this.up('form').getForm();
264 fields = form.getFields();
265 fields.each(function(field){
266 if (field.name != 'company') {
267 field.setDisabled(false);
271 fields = form.getFields();
274 // prevent change events from firing
275 fields.each(function(field){
276 field.suspendEvents();
278 form.loadRecord(rec);
280 fields.each(function(field){
281 field.resumeEvents();
288 //create a bar series to be at the top of the panel.
289 var barChart = Ext.create('Ext.chart.Chart', {
305 renderer: function(v) {
306 return Ext.String.ellipsis(v, 15, false);
326 display: 'insideEnd',
329 orientation: 'vertical',
330 'text-anchor': 'middle'
333 'itemmouseup': function(item) {
334 var series = barChart.series.get(0),
335 index = Ext.Array.indexOf(series.items, item),
336 selectionModel = gridPanel.getSelectionModel();
338 selectedStoreItem = item.storeItem;
339 selectionModel.select(index);
347 //disable highlighting by default.
348 barChart.series.get(0).highlight = false;
350 //add listener to (re)select bar item after sorting or refreshing the dataset.
351 barChart.addListener('beforerefresh', (function() {
355 if (selectedStoreItem) {
356 timer = setTimeout(function() {
357 selectItem(selectedStoreItem);
364 * Here is where we create the Form
366 var gridForm = Ext.create('Ext.form.Panel', {
367 title: 'Company data',
392 layout: {type: 'hbox', align: 'stretch'},
395 bodyStyle: 'background-color: transparent',
404 title: 'Company Details',
409 title:'Company details',
415 defaultType: 'numberfield',
425 enforceMaxLength: true,
427 listeners: createListeners('price')
429 fieldLabel: 'Revenue %',
433 enforceMaxLength: true,
435 listeners: createListeners('revenue %')
437 fieldLabel: 'Growth %',
441 enforceMaxLength: true,
443 listeners: createListeners('growth %')
445 fieldLabel: 'Product %',
449 enforceMaxLength: true,
451 listeners: createListeners('product %')
453 fieldLabel: 'Market %',
457 enforceMaxLength: true,
459 listeners: createListeners('market %')
467 var gp = Ext.getCmp('company-form');