Adding Pie Charts to Sencha Touch2 Application - extjs

I am trying to add pie chart to the existing sencha touch mvc application , pie chart displays fine if i place the chart related code in the app.js file , The problem i am facing is if place the chart in seperate view its not displaying , i dont see any errors also being triggered, Please can i know is their any different approach to integrate pie chart for different views?
This my sample code of the view where piechart code is written
Ext.define('Example.view.PieChartTest', {
extend: 'Ext.Panel',
xtype: "piecharttestpage",
requires: [
'Ext.chart.Panel',
'Ext.chart.axis.Numeric',
'Ext.chart.axis.Category',
'Ext.chart.series.Pie'
],
intit: function () {
//this.callParent(arguments);
window.initExample = function (title, helpText, defaultStore) {
defaultStore = defaultStore || 'store1';
window.generateData = function (n, floor) {
var data = [],
i;
floor = (!floor && floor !== 0) ? 20 : floor;
for (i = 0; i < (n || 12); i++) {
data.push({
name: Ext.Date.monthNames[i % 12],
data1: Math.floor(Math.max((Math.random() * 100), floor)),
data2: Math.floor(Math.max((Math.random() * 100), floor)),
data3: Math.floor(Math.max((Math.random() * 100), floor)),
2003: Math.floor(Math.max((Math.random() * 100), floor)),
2004: Math.floor(Math.max((Math.random() * 100), floor)),
2005: Math.floor(Math.max((Math.random() * 100), floor)),
2006: Math.floor(Math.max((Math.random() * 100), floor)),
2007: Math.floor(Math.max((Math.random() * 100), floor)),
2008: Math.floor(Math.max((Math.random() * 100), floor)),
2009: Math.floor(Math.max((Math.random() * 100), floor)),
2010: Math.floor(Math.max((Math.random() * 100), floor)),
iphone: Math.floor(Math.max((Math.random() * 100), floor)),
android: Math.floor(Math.max((Math.random() * 100), floor)),
ipad: Math.floor(Math.max((Math.random() * 100), floor))
});
}
return data;
};
window.store1 = new Ext.create('Ext.data.JsonStore', {
fields: ['name', '2004', '2005', '2006', '2007', '2008', '2009', '2010', 'iphone', 'android', 'ipad'],
data: generateData(5, 20)
});
window.store2 = new Ext.data.JsonStore({
fields: ['name', '2008', '2009', '2010', 'data4', 'data5', 'data6', 'data7', 'data8', 'data9'],
data: generateData(6, 20)
});
window.store3 = new Ext.data.JsonStore({
fields: ['name', '2007', '2008', '2009', '2010'],
data: generateData(12, 20)
});
var onRefreshTap = function () {
window[defaultStore].setData(generateData(window[defaultStore].data.length, 20));
};
var onHelpTap = function () {
window.helpPanel = window.helpPanel || Ext.create('Ext.Panel', {
ui: 'dark',
modal: true,
fullscreen: false,
hideOnMaskTap: true,
centered: true,
width: 300,
height: 250,
styleHtmlContent: true,
scrollable: 'vertical',
zIndex: 100,
items: [
{
docked: 'top',
xtype: 'toolbar',
title: title
},
{
html: helpText,
hidden: !helpText
}
]
});
window.helpPanel.show('pop');
};
window.createPanel = function (chart) {
return window.panel = Ext.create('Ext.chart.Panel', {
fullscreen: true,
title: title,
buttons: [
{
xtype: 'button',
iconCls: 'help',
iconMask: true,
ui: 'plain',
handler: onHelpTap
},
{
xtype: 'button',
iconCls: 'shuffle',
iconMask: true,
ui: 'plain',
handler: onRefreshTap
}
],
chart: chart
});
};
};
window.createPanel(new Ext.chart.Chart({
themeCls: 'pie1',
theme: 'Demo',
store: store1,
shadow: false,
animate: true,
insetPadding: 20,
legend: {
position: 'left'
},
interactions: [{
type: 'piegrouping',
listeners: {
selectionchange: function (interaction, selectedItems) {
var sum = 0,
i = selectedItems.length;
if (i) {
while (i--) {
sum += selectedItems[i].storeItem.get('visitors');
}
window.chartPanel.descriptionPanel.setTitle('Total visitors: ' + sum);
window.chartPanel.headerPanel.setActiveItem(1, { type: 'slide', direction: 'left' });
}
else {
window.chartPanel.headerPanel.setActiveItem(0, { type: 'slide', direction: 'right' });
}
}
}
}],
series: [
{
type: 'pie',
field: '2007',
showInLegend: true,
highlight: false,
listeners: {
'labelOverflow': function (label, item) {
item.useCallout = true;
}
},
// Example to return as soon as styling arrives for callouts
callouts: {
renderer: function (callout, storeItem) {
callout.label.setAttributes({
text: storeItem.get('name')
}, true);
},
filter: function () {
return false;
},
box: {
//no config here.
},
lines: {
'stroke-width': 2,
offsetFromViz: 20
},
label: {
font: 'italic 14px Arial'
},
styles: {
font: '14px Arial'
}
},
label: {
field: 'name'
}
}
]
}));
// this.add(chartpanel);
},
config: {
title: 'info',
iconCls: 'star',
scrollable: true,
cls: 'servicesclass',
layout: 'vbox',
height: 500,
width: 500,
autoDestroy: true
}
});

I know this issue you can fix it by converting things in variable. Try the code below in your view section and change the name of the app to your app
generateData = function(n) {
var data = [];
var names = ['one', 'two', 'three', 'four'];
var i;
for (i = 0; i < n; i++) {
data.push({description: names[i], value: 3 + i}); //pushes data onto the data array by looping, value is a funciton of i
}
return data;
};
var myStore = new Ext.create('Ext.data.Store', {
fields: ['description', 'value'],
data: generateData(4)
});
var chart1 = new Ext.create('Ext.chart.Chart', {
store: myStore, //the store that it will use
height: 480,
width: 320,
series: [{
type: 'pie',
showInLegend: true,
field: 'value',
label: { //the label inside each pie
field: 'description',
font: '20px Arial',
display: 'rotate',
contrast: true
},
}],
});
Ext.define('MyApp.view.panel1', {
extend: 'Ext.chart.Panel',
alias: 'widget.Panel1',
config:
{
chart: chart1 //displays the chart
}
});
Tut the name of this panel i.e Panel1 in the App.js file
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
views: [
'panel1',
],
name: 'MyApp',
controllers: [
'your controller name'
],
// include this one only if you have MainNav
launch: function() {
Ext.create('MyApp.view.MainNav', {fullscreen: true});
}
});
This one works for me.

first make sure that you're referencing the sencha touch library inside the sencha touch distribution, not the main sencha touch library you can download in your html.
secondly you'll save yourself a lot of headache if you use MVCS folders and learn how to use the new references in ST2 and it will make debugging this 1000 times easier.
also you are using globals (window.)??

Related

Ext Js ChartsKitchenSink.view.charts.pie.Basic

I'm using this pie chart example in this link to display a pie chart.
How do I set the pie chart dynamically and refresh the pie chart?
To dynamically create chart:-
var chart = Ext.create('Ext.chart.Chart', {
xtype: 'chart',
animate: true,
store: store1,
shadow: true,
legend: {
position: 'right'
},
insetPadding: 60,
theme: 'Base:gradients',
series: [{
type: 'pie',
field: 'data1',
showInLegend: true,
donut: donut,
tips: {
trackMouse: true,
renderer: function(storeItem, item) {
//calculate percentage.
var total = 0;
store1.each(function(rec) {
total += rec.get('data1');
});
this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data1') / total * 100) + '%');
}
},
highlight: {
segment: {
margin: 20
}
},
label: {
field: 'name',
display: 'rotate',
contrast: true,
font: '18px Arial'
}
}]
});
To refresh the chart you can use store.loadData method.
Reference url
For loading dynamic data in pie char store you can use reload(),loadData() and load() methods of store.
store.reload() example
store.reload({
params : {
userid : 1234
}
});
store.load() example
store.load({
scope: this,
callback: function(records, operation, success) {
// the Ext.data.operation.Operation object
// contains all of the details of the load operation
console.log(records);
}
});
If the callback scope does not need to be set, a function can simply be passed:
store.load(function(records, operation, success) {
console.log('loaded records');
});
store.loadData() example
var data= [{
os: 'Android',
data1: 68.3
},{
os: 'Others',
data1: 1.9
}];
store.loadData(data);
In this FIDDLE, I have created a demo. Hope this will help/guide you to achieve your requirement.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
/**
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function createDyanmicData(store) {
store.each(rec => {
rec.set('data1', getRandomInt(20, 100));
});
}
Ext.create({
xtype: 'polar',
tbar: ['->', {
text: 'Refresh Chart',
height: 35,
padding: 5,
margin:'0 10',
style: {
background: 'green'
},
handler: function () {
createDyanmicData(this.up('polar').getStore())
}
}],
title: 'Pie Chart Example',
renderTo: Ext.getBody(),
width: '100%',
height: window.innerHeight,
interactions: 'rotate',
store: {
fields: ['os', 'data1'],
data: [{
os: 'Android',
data1: 68.3
}, {
os: 'iOS',
data1: 17.9
}, {
os: 'Windows Phone',
data1: 10.2
}, {
os: 'BlackBerry',
data1: 1.7
}, {
os: 'Others',
data1: 1.9
}]
},
series: {
type: 'pie',
xField: 'data1',
label: {
field: 'os',
display: 'inside',
calloutLine: true
},
showInLegend: true,
highlight: true,
highlightCfg: {
fill: '#ccc',
'stroke-width': 10,
stroke: '#fff'
},
tips: {
trackMouse: true,
renderer: function (storeItem, item) {
this.setTitle(storeItem.get('os') + ': ' + storeItem.get('data1') + '%');
}
}
}
});
}
});

Cannot bind filters on Ext.chart.CartesianChart

I am new to Ext JS working on Sencha 6.5(Ext js 6.2), while running my code I am getting error as :
Ext.mixin.Bindable.applyBind(): Cannot bind filters on Ext.chart.CartesianChart - missing a setFilters method.
The chart in tab1 works fine. Further what I am trying to do is, binding the selection from combo box in tab2 to cartesian chart in next tab, I am getting the error. Can any one help please, Thanks in advance, my code is :
Store : 2FAData.js
Ext.define('LICApp.store.2FAData', {
extend: 'Ext.data.Store',
alias: 'store.2fa-data',
storeId: 'myStore',
requires: [
'Ext.data.reader.Xml'
],
autoLoad: false, // Set it to false
fields: ['name','cnt', 'zone'],
proxy: {
type: 'rest',
cors: 'true',
url : 'http://localhost:8080/UserManagement/rest/BiodataController/bio',
method: 'POST',
reader: {
type: 'xml',
record: 'biodata',
rootProperty: 'biodatas'
}
}
});
Basic.js
Ext.define('LICApp.view.charts.bar3d.Basic', {
extend: 'Ext.tab.Panel',
xtype: 'bar-basic-3d',
controller: 'bar-basic-3d',
requires: [
'Ext.chart.theme.Muted',
'LICApp.store.2FAData',
'LICApp.store.Chartdata'
],
//width: 1300,
layout: 'anchor',
defaults: { anchor: '-30' },
referenceHolder: true,
viewModel: true,
config: {
value: false
},
items: [{
xtype: 'cartesian',
title: 'Consolidated View',
reference: 'chart',
theme: 'Muted',
width: '100%',
height: 700,
legend: {
docked: 'right'
},
animation: Ext.isIE8 ? false : {
easing: 'backOut',
duration: 500
},
store: {type: 'chartdata',autoLoad:true},
insetPadding: 40,
flipXY: true,
axes: [{
type: 'numeric3d',
position: 'bottom',
grid: true,
minimum: 0,
//maximum: 100,
//majorTickSteps: 10,
renderer: 'onAxisLabelRender1'
}, {
type: 'category3d',
position: 'left',
grid: true
}],
series: [{
type: 'bar3d',
fullStack: false,
title: [ 'Concurrencia Enabled', 'eFeap Enabled', 'Authorised Users', 'Biometric Enrolled Users', 'Total Devices Issued', 'Total No. of Employees'],
xField: 'zone',
yField: [ 'data1', 'data2', 'data3', 'data4', 'data5', 'data6'],
axis: 'bottom',
stacked: false,
highlight: true,
tooltip: {
trackMouse: true,
renderer: 'onSeriesTooltipRender1'
}
}],
sprites: [{
type: 'text',
text: '2FA Biometric Progress - Zonewise comparison',
fontSize: 22,
width: 100,
height: 30,
x: 450, // the sprite x position
y: 20 // the sprite y position
},
{
type: 'text',
text: 'Source: 2FA Data Server',
fontSize: 10,
x: 12,
y: 695
}]
},
{
xtype: 'combobox',
title : 'Zone Selection',
reference: 'zone',
fieldLabel: 'Choose Zone',
store: {
type: 'chartdata',autoLoad:true
},
valueField: 'zone',
displayField: 'zone',
publishes: 'value',
typeAhead: true,
queryMode: 'local',
triggerAction: 'all',
emptyText: 'Select a Zone...',
selectOnFocus: true,
//width: 300,
indent: true,
renderTo: Ext.getBody(),
listeners: {
select: 'onZoneSelected'
}
},
{
xtype: 'cartesian',
itemId: 'zchart',
title: 'Zonewise View',
flipXY: true,
reference: 'chart',
width: '100%',
height: 500,
insetPadding: '40 40 30 40',
innerPadding: '3 0 0 0',
theme: {
type: 'muted'
},
store: {
type: '2fa-data', autoLoad :true
},
bind: {
visible: '{zone.value}',
filters: {
property: 'zone',
value: '{zone.value}'
}
},
animation: {
easing: 'easeOut',
duration: 500
},
interactions: ['itemhighlight'],
axes: [{
type: 'numeric3d',
renderer: 'onAxisLabelRender',
title: 'Number of Employees',
grid: {
odd: {
fillStyle: 'rgba(245, 245, 245, 1.0)'
},
even: {
fillStyle: 'rgba(255, 255, 255, 1.0)'
}
}
}, {
type: 'category3d',
position: 'left',
label: {
textAlign: 'right'
},
grid: true
}],
series: [{
type: 'bar3d',
xField: 'name',
yField: 'cnt',
style: {
minGapWidth: 10
},
highlight: true,
label: {
field: 'cnt',
display: 'insideEnd',
renderer: 'onSeriesLabelRender'
},
tooltip: {
trackMouse: true,
renderer: 'onSeriesTooltipRender'
}
}],
sprites: [{
type: 'text',
text: '2FA Biometric - Zonewise Progress Chart',
fontSize: 22,
width: 100,
height: 30,
x: 40, // the sprite x position
y: 20 // the sprite y position
}, {
type: 'text',
text: 'Source: 2FA Data Server',
fontSize: 10,
x: 12,
y: 490
}]
}
]
});
BasicController.js
Ext.define('LICApp.view.charts.bar3d.BasicController', {
extend: 'Ext.app.ViewController',
alias: 'controller.bar-basic-3d',
onAxisLabelRender: function (axis, label, layoutContext) {
return Ext.util.Format.number(layoutContext.renderer(label) );
},
onSeriesLabelRender: function (v) {
return Ext.util.Format.number(v);
},
onSeriesTooltipRender: function (tooltip, record, item) {
var formatString = '0,000 ';
tooltip.setHtml(record.get('name') + ': ' +
Ext.util.Format.number(record.get('cnt'), formatString));
},
onPreview: function () {
if (Ext.isIE8) {
Ext.Msg.alert('Unsupported Operation', 'This operation requires a newer version of Internet Explorer.');
return;
}
var chart = this.lookupReference('chart');
chart.preview();
},
onItemSelected: function (sender, record) {
var zone = sender.getValue();
Ext.toast('You selected : ' + zone);
var store = Ext.getStore('myStore');
Ext.Ajax.request({
url: 'http://localhost:8080/UserManagement/rest/BiodataController/bio?zone='+zone,
timeout: 60000,
method: 'GET',
scope: this,
reader: {
type: 'xml',
record: 'biodata',
rootProperty: 'biodatas'
},
success: function(resp, request) {
var data = console.log(resp.responseText);
var myView = Ext.getCmp('zchart');
Ext.MessageBox.alert('Success', 'Data return from the server: '+ resp.responseText);
store.reLoad();//reload will be called, when AJAX call is successful.
/*
if ( window.DOMParser ) { // Standard
tmp = new DOMParser();
xml = tmp.parseFromString( resp.responseText , "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false";
xml.loadXML( resp.responseText );
}
*/
autoLoad:true;
//store.load(resp.responseText);
//console.log(myView);
//store.setData(resp.responseText);
},
failure: function(resp, opts) {
},
callback: function(options, success, resp) {
}
});
},
onCombo1Selected: function (sender, record) {
var zone = sender.getValue();
Ext.toast('You selected : ' + zone );
},
onCombo2Selected: function (sender, record) {
var divn = sender.getValue();
Ext.toast('You selected : ' + divn + '-' + record.get('donm'));
},
onCombo3Selected: function (sender, record) {
var bran = sender.getValue();
Ext.toast('You selected : ' + record.get('bran'));
},
onZoneSelected: function (sender, record) {
var zone = sender.getValue();
Ext.toast('You selected : ' + zone );
},
// Controller entries for stacked bar
onAxisLabelRender1: function (axis, label, layoutContext) {
// Custom renderer overrides the native axis label renderer.
// Since we don't want to do anything fancy with the value
// ourselves except appending a '%' sign, but at the same time
// don't want to loose the formatting done by the native renderer,
// we let the native renderer process the value first.
return layoutContext.renderer(label) ;
},
onSeriesTooltipRender1: function (tooltip, record, item) {
var fieldIndex = Ext.Array.indexOf(item.series.getYField(), item.field),
zone = item.series.getTitle()[fieldIndex];
tooltip.setHtml(zone + ' of ' + record.get('zone') + ': ' +
record.get(item.field) + ' out of ' + record.get('data6') + ' Total');
},
onColumnRender1: function (v) {
return v ;
}
// Ends here
});
This won't work the way you want it to.
The Cartesian Graph doesn't have it's own filtering mechanism and thus you can't trigger the filter via data binding. (Correct me if I'm wrong, but as far as I know, you can't set child elements' properties such as the store's filter property via data-binding)
You'll have to take the oldschool route and set the filters by hand in the ComboBox's Listener like this:
onZoneSelected: function (sender, record) {
var zone = sender.getValue();
Ext.toast('You selected : ' + zone );
var zchart = sender.up().getComponent('#zchart');
zchart.store.setFilters([{property: 'zone', value: zone}]);
},

Scroll and expand are not working properly

We have one grid panel within Ext.Window. The scroll bar of gridpanel is automatically moving up while scrolling it isn't working properly and when Ext.Window is expanded the grid panel is not expanding. I guess some property has to be set?. Will using autoExpandColumn in gridpanel solve the problem?
extWin=new Ext.Window({
title:"Locate Managed Object",items:[new Ext.grid.GridPanel({
title: "Managed Elements",
region: "center",
height:250,
width:500, renderTo:"tree-id",
viewConfig: {forceFit: true},
store: store,
sm: new GeoExt.grid.FeatureSelectionModel({selectControlelect}),
cm: new Ext.grid.ColumnModel({
defaults: {
sortable: true
},
columns: [
{header:"Managed Elements",dataIndex:"fid"}
]
})
})]
});
extWin.show();
I have added layout:'fit' to this and expanded is working fine but scroll isn't working. Please correct if I'm wrong at any point.
Here is the working example. If you encounter any problem, let me know.
The trick is, layout property. Just set container's layout property fit ( in this case container is window ) and don't give any size property for grid, like width, height.
Sencha Fiddle - GridPanel in Window
Ext.onReady(function(){
function createFakeData(count) {
var firstNames = ['Ed', 'Tommy', 'Aaron', 'Abe', 'Jamie', 'Adam', 'Dave', 'David', 'Jay', 'Nicolas', 'Nige'],
lastNames = ['Spencer', 'Maintz', 'Conran', 'Elias', 'Avins', 'Mishcon', 'Kaneda', 'Davis', 'Robinson', 'Ferrero', 'White'],
ratings = [1, 2, 3, 4, 5],
salaries = [100, 400, 900, 1500, 1000000];
var data = [];
for (var i = 0; i < (count || 25); i++) {
var ratingId = Math.floor(Math.random() * ratings.length),
salaryId = Math.floor(Math.random() * salaries.length),
firstNameId = Math.floor(Math.random() * firstNames.length),
lastNameId = Math.floor(Math.random() * lastNames.length),
rating = ratings[ratingId],
salary = salaries[salaryId],
name = Ext.String.format("{0} {1}", firstNames[firstNameId], lastNames[lastNameId]);
data.push({
rating: rating,
salary: salary,
name: name
});
}
return data;
}
Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [
{name: 'rating', type: 'int'},
{name: 'salary', type: 'float'},
{name: 'name'}
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
id: 'store',
pageSize: 50,
buffered: true,
purgePageCount: 0,
model: 'Employee',
proxy: {
type: 'memory'
}
});
Ext.create('Ext.window.Window', {
title: 'Hello',
height: 500,
width: 400,
closable: false,
collapsible: true,
layout: {
type: 'fit'
},
items: {
xtype: 'grid',
border: false,
store: store,
loadMask: true,
disableSelection: true,
invalidateScrollerOnRefresh: false,
viewConfig: {
trackOver: false
},
columns: [
{xtype:'rownumberer',width:40,sortable:false},
{text: 'Name',flex:1,sortable:true,dataIndex:'name'},
{text: 'Rating',width:125,sortable:true,dataIndex:'rating'},
{text: 'Salary',width:125,sortable:true,dataIndex:'salary',align:'right',renderer:Ext.util.Format.usMoney}
]}
}).show();
var data = createFakeData(500),
ln = data.length,
records = [],
i = 0;
for (; i < ln; i++) {
records.push(Ext.ModelManager.create(data[i], 'Employee'));
}
store.loadData(records);
});

How to use SmartLegend on Sencha chart

I am researching how to use smart legend on sencha chart but legend not show multi columns
I am so stupid. Please help me .
Thank all
Nguyen
Ext.onReady(function () {
var panel, chart, legend,
store = Ext.create('Ext.data.Store', {
fields: [ 'name', 'data' ],
data: [
{ name: 'Field 0', data: Math.random() * 100 },
{ name: 'Field 1', data: Math.random() * 100 },
{ name: 'Field 2', data: Math.random() * 100 },
{ name: 'Field 3', data: Math.random() * 100 },
{ name: 'Field 4', data: Math.random() * 100 },
{ name: 'Field 5', data: Math.random() * 100 },
{ name: 'Field 6', data: Math.random() * 100 },
{ name: 'Field 7', data: Math.random() * 100 },
{ name: 'Field 8', data: Math.random() * 100 },
{ name: 'Field 9', data: Math.random() * 100 },
{ name: 'Field 10', data: Math.random() * 100 },
{ name: 'Field 11', data: Math.random() * 100 },
{ name: 'Field 12', data: Math.random() * 100 }
]
});
chart = Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
position: 'absolute',
id:'chart',
x: 100,
y: 100,
layout: 'fit',
width: 800,
height: 850,
animate: true,
store: store,
theme: 'Base:gradients',
animate: Ext.isIE ? false : true,
store: store,
shadow: Ext.isIE ? false : true,
legend: false,
series: [{
type: 'pie',
id : 'chart',
field: 'data',
showInLegend: true,
tips: {
trackMouse: true,
width: 140,
height: 28,
renderer: function(storeItem, item) {
// calculate and display percentage on hover
var total = 0;
store.each(function(rec) {
total += rec.get('data');
});
this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data') / total * 100) + '%');
}
},
highlight: {
segment: {
margin: 20
}
},
label: {
field: 'name',
display: 'rotate',
contrast: true,
font: '18px Arial'
}
}]
});
//chart =this.down('chart'); //panel.down('chart');
legend = chart.legend = Ext.create('Ext.ux.chart.SmartLegend', {
position: 'right',
chart: chart,
rebuild: true,
boxStrokeWidth: 1
});
chart.legend.redraw();
chart.redraw();
});
Another alternative on sencha forums: ExtJS 4 chart legend sizing

Need to convert ExtJs sample app to MVC application

i have a problem with this example see this link
http://dev.sencha.com/deploy/ext-4.0.0/examples/grid/buffer-grid.html
i want to convert in MVC application. So anybody please help me .
Firstly your model in your app/model folder
Ext.define('AppName.model.Employee', {
extend: 'Ext.data.Model',
fields: [
{name: 'rating', type: 'int'},
{name: 'salary', type: 'float'},
{name: 'name'}
]
});
and store in your app/store folder
Ext.define('AppName.store.Employee', {
extend:'Ext.data.Store',
buffered: true,
pageSize: 5000,
model: 'Employee',
proxy: { type: 'memory' }
});
And your grid view in your app/view folder
Ext.define('AppName.view.EmployeeGrid', {
alias:'employeegrid',
extend:'Ext.grid.Panel',
width: 700,
height: 500,
title: 'Bufffered Grid of 5,000 random records',
store: 'Employee',
loadMask: true,
disableSelection: true,
viewConfig: { trackOver: false },
columns:[{
xtype: 'rownumberer',
width: 40,
sortable: false
},{
text: 'Name',
flex:1 ,
sortable: true,
dataIndex: 'name'
},{
text: 'Rating',
width: 125,
sortable: true,
dataIndex: 'rating'
},{
text: 'Salary',
width: 125,
sortable: true,
dataIndex: 'salary',
align: 'right',
renderer: Ext.util.Format.usMoney
}]
});
And your controller in your app/controller folder
Ext.define('AppName.controller.Employee',{
extend:'Ext.app.Controller',
stores:['Employee'],
views:['EmployeeGrid'],
refs:[
{ref:'employeeGrid',selector:'employeegrid'}
],
init:function(){
var me = this;
me.getEmployeeStore().loadData(me.createFakeData(5000));
},
createFakeData:function(count) {
var firstNames = ['Ed', 'Tommy', 'Aaron', 'Abe', 'Jamie', 'Adam', 'Dave', 'David', 'Jay', 'Nicolas', 'Nige'],
lastNames = ['Spencer', 'Maintz', 'Conran', 'Elias', 'Avins', 'Mishcon', 'Kaneda', 'Davis', 'Robinson', 'Ferrero', 'White'],
ratings = [1, 2, 3, 4, 5],
salaries = [100, 400, 900, 1500, 1000000];
var data = [];
for (var i = 0; i < (count || 25); i++) {
var ratingId = Math.floor(Math.random() * ratings.length),
salaryId = Math.floor(Math.random() * salaries.length),
firstNameId = Math.floor(Math.random() * firstNames.length),
lastNameId = Math.floor(Math.random() * lastNames.length),
rating = ratings[ratingId],
salary = salaries[salaryId],
name = Ext.String.format("{0} {1}", firstNames[firstNameId], lastNames[lastNameId]);
data.push({
rating: rating,
salary: salary,
name: name
});
}
return data;
}
});
Funally u have to create App in your app folder
Ext.application({
requires:[
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.grid.PagingScroller',
'AppName.view.EmployeeGrid'
],
name:'AppName',
models:['Employee'],
stores:['Employee'],
controllers:['Employee'],
launch:function () {
Ext.onReady(function(){
Ext.create('Ext.Viewport', {
layout: 'fit',
items:[{xtype:'emplyeegrid'}]
});
});
}
});

Resources