When using ExtJS to develop the application system, it is inevitable that a JS file contains hundreds of lines or even thousands of lines of code, such as the main interface of the program or a complex interface, the following describes how to reduce the number of individual ExtJS JavaScript lines of code by customizing the component method.
The main interface in the display shows two charts:
At first, the JS code of the chart was written to die inside the Tagpanel, and the code of the ExtJS custom component was split into a separate class file:
Ext.define (' App.view.main.Main_Pie_Chart ', {extend: ' Ext.panel.Panel ', alias: ' Widget.main_pie_chart ', Chart_store: Null,layout: {type: ' Fit '},initcomponent:function () {var me = this; Ext.applyif (Me, {title: ' Inventory Commodity cost Distribution Pie chart ', Items:[{xtype: ' Chart ',//region: ' Center ', animate:true,width:450,height:400, Store:me.chart_store,shadow:true,legend: {position: ' Right '},insetpadding:60,theme: ' Base:gradients ', series: [{ Type: ' Pie ', field: ' Data1 ', showinlegend:true,donut:35,tips: {trackmouse:true,width:140,height:28,renderer: function (Storeitem, item) {//var total = 0;//storeitem.each (function (REC) {//Total + = Rec.get (' data1 ');/});//this.set Title (Storeitem.get (' product_name ') + ': ' + math.round (storeitem.get (' data1 ')/total *) + '% '); This.settitle (Storei Tem.get (' product_name ') + ': ' +storeitem.get (' data1 ') + ' meta-inventory cost ');}},highlight: {segment: {margin:20}},label: {field: ' Product_Name ', display: ' Rotate ', Contrast:true,font: ' 18px Arial '}}]}]}); me.callparent (arguments);});
The above code defines a class called "App.view.main.Main_Pie_Chart", which needs to be imported with requires in TabPanel, see the following code:
Ext.Define(' App.view.Viewport ', {Renderto: Ext.GetBody(), Extend:' Ext.container.Viewport ', alias:' Widget.main_viewport ', requires: [' Ext.tab.Panel ', ' Ext.layout.container.Border ', ' App.store.StockChartPieStore ', ' App.view.main.Main_Top_Panel ', ' App.view.main.Main_Pie_Chart ', ' App.view.main.Main_Column_Chart ' ], Layout: {type:' border ' },
The code used in the TabPanel of the main interface can be simplified to:
{xtype:' TabPanel ', Region:"Center", ID:' Content_tabpanel ', margins:' 2 5 5 0 ', Activetab:0, Border:false, Items: [{ID:' Start-panel ', title:' Welcome to use ', Layout:' Hbox ', bodystyle:' padding:25px; Background-image:url (./img/bg.jpg); background-repeat:no-repeat; background-attachment:fixed; background-position:100% 100% ', Items: [ {xtype:' Main_pie_chart ', Chart_store: Chart_data_store}, {xtype:' Main_column_chart ', Chart_store: Chart_data_store}]}
Note that this is actually a reference to the two custom ExtJS Chart component classes, two graphs corresponding to the same store, so after writing xtype to reference the custom component, and then provide Chart_store this ExtJS custom class properties.
ExtJS Custom Component Classes