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.
15 Ext.require('Ext.chart.*');
17 Ext.onReady(function () {
19 var generateData = (function() {
22 date = new Date(2011, 1, 1),
30 date: Ext.Date.add(date, Ext.Date.DAY, i++),
31 visits: min(100, max(last? last.visits + (random() - 0.5) * 20 : random() * 100, 0)),
32 views: min(100, max(last? last.views + (random() - 0.5) * 10 : random() * 100, 0)),
33 users: min(100, max(last? last.users + (random() - 0.5) * 20 : random() * 100, 0))
35 last = data[data.length -1];
43 groupBy: 'year,month,day'
51 var axis = chart.axes.get(1),
52 selectedGroup = groupOp[+group];
53 axis.dateFormat = selectedGroup.dateFormat;
54 axis.groupBy = selectedGroup.groupBy;
58 var store = Ext.create('Ext.data.JsonStore', {
59 fields: ['date', 'visits', 'views', 'users'],
63 var intr = setInterval(function() {
64 var gs = generateData();
65 var toDate = timeAxis.toDate,
66 lastDate = gs[gs.length - 1].date,
67 markerIndex = chart.markerIndex || 0;
68 if (+toDate < +lastDate) {
70 timeAxis.toDate = lastDate;
71 timeAxis.fromDate = Ext.Date.add(Ext.Date.clone(timeAxis.fromDate), Ext.Date.DAY, 1);
72 chart.markerIndex = markerIndex;
77 Ext.create('Ext.Window', {
84 title: 'Live Animated Chart',
85 renderTo: Ext.getBody(),
89 style: 'background:#fff',
100 fields: ['views', 'visits', 'users'],
101 title: 'Number of Hits',
115 groupBy: 'year,month,day',
119 fromDate: new Date(2011, 1, 1),
120 toDate: new Date(2011, 1, 7),
126 axis: ['left', 'bottom'],
132 renderer: function(v) { return v >> 0; },
133 'text-anchor': 'middle'
141 axis: ['left', 'bottom'],
148 renderer: function(v) { return v >> 0; },
149 'text-anchor': 'middle'
157 axis: ['left', 'bottom'],
164 renderer: function(v) { return v >> 0; },
165 'text-anchor': 'middle'
174 chart = Ext.getCmp('chartCmp');
175 var timeAxis = chart.axes.get(1);