新聞中心
這篇文章主要介紹了extjs圖形如何繪制之餅圖,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
建網(wǎng)站原本是網(wǎng)站策劃師、網(wǎng)絡(luò)程序員、網(wǎng)頁(yè)設(shè)計(jì)師等,應(yīng)用各種網(wǎng)絡(luò)程序開發(fā)技術(shù)和網(wǎng)頁(yè)設(shè)計(jì)技術(shù)配合操作的協(xié)同工作。創(chuàng)新互聯(lián)專業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站制作(企業(yè)站、響應(yīng)式網(wǎng)站建設(shè)、電商門戶網(wǎng)站)等服務(wù),從網(wǎng)站深度策劃、搜索引擎友好度優(yōu)化到用戶體驗(yàn)的提升,我們力求做到極致!
具體如下:
這篇文章將介紹extjs中自帶的餅圖。
代碼如下:
Ext.define('ChartPieTest', { extend: 'Ext.panel.Panel', autoScroll : true, initComponent: function () { var me = this; me.store = me.createStore(); me.grid = me.getGridPanel(); me.mainPanel = Ext.create('Ext.panel.Panel',{ layout:'fit', items:[me.grid], }); Ext.apply(me,{ layout:'fit', items:[me.mainPanel] }); me.callParent(); me.mainPanel.down('chart').on('cellclick', function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) { me.onCellClick(cellIndex, record); }); }, getGridPanel:function(){ var me = this; return { xtype:'chart', insetPadding: 40, animate : true,// 是否支持動(dòng)態(tài)數(shù)據(jù)變化 legend: {// 圖例 position: "right", spacing: 12, padding: 5, font: { name: 'Tahoma', color: '#3366FF', size: 12, bold: true } }, store:me.store, //axes:me.createAxes(), series:me.createSeries(), } }, createStore: function () { var me = this; return Ext.create('Ext.data.JsonStore', { //從后端請(qǐng)求數(shù)據(jù) /* fields: [ {name: 'id', mapping: 'id'}, {name:'statTime',mapping:'statTime',type:'date',dateFormat:'time'}, 'activeCount', 'effectiveCount','effectiveProportion', ], proxy: { type: 'ajax', url: ctx+'/mvc/com/analyze/tblVwMonthUserStat', reader: { type: 'json', root: 'root', totalProperty: 'totalProperty' } }, listeners: { 'beforeload': function (store, operation, eOpts) { store.proxy.extraParams.selectYear = me.selectYear } },*/ //自己模擬數(shù)據(jù) fields: ['name', 'data'], data: [ { 'name': '中年人', 'data': 10 }, { 'name': '嬰兒', 'data': 7 }, { 'name': '老年人', 'data': 5 }, { 'name': '小孩', 'data': 2 }, { 'name': '青少年', 'data': 27 } ], autoLoad: true }); }, createSeries: function () { var me = this; var columns = [ { type: 'pie', angleField: 'data', showInLegend: true, tips: { trackMouse: true, width: 140, height: 40, renderer: function(storeItem, item) { // calculate and display percentage on hover var total = 0; me.store.each(function(rec) { total += rec.get('data'); }); this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data') / total * 100) + '%'); } }, highlight: { segment: { margin: 5 } }, label: { field: 'name', display: 'rotate', contrast: true, font: '18px Arial' } }, ]; return columns; } });
注:
1.上面中的createStore是創(chuàng)建餅圖所需要的數(shù)據(jù)的--store。
2.上面中的legend 顯示的右邊的圖例(表明哪塊代表什么數(shù)據(jù)),legend中的position屬性可以調(diào)節(jié)圖例的位置。其中有‘left'、‘right',‘bottom'、‘top'分別代表左右下上位置。
3.showInLegend是bool值,為false的時(shí)候不顯示上面的圖例。
4.tips這里是當(dāng)鼠標(biāo)放在餅圖上的時(shí)候顯示的提示性文字,其中的renderer方法中可設(shè)置提示哪些內(nèi)容。
5.label 設(shè)置餅圖上顯示文字的一些屬性。其中的display屬性決定文字在餅圖中位置,共有‘outside'、‘rotate'兩種方式,前者表示文字顯示在圖表的外邊,后者文字顯示在圖表的里邊。
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“extjs圖形如何繪制之餅圖”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
分享標(biāo)題:extjs圖形如何繪制之餅圖
URL分享:http://fisionsoft.com.cn/article/gigcds.html