extjs圖形繪制之餅圖實(shí)現(xiàn)方法分析
本文實(shí)例講述了extjs圖形繪制之餅圖實(shí)現(xià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,// 是否支持動態(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', { //從后端請求數(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'兩種方式,前者表示文字顯示在圖表的外邊,后者文字顯示在圖表的里邊。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript運(yùn)動效果與技巧匯總》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
js?字符串反轉(zhuǎn)(倒序)的幾種方式總結(jié)
這篇文章主要介紹了js?字符串反轉(zhuǎn)(倒序)的幾種方式總結(jié),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10js網(wǎng)頁中的(運(yùn)行代碼)功能實(shí)現(xiàn)思路
網(wǎng)頁中的"運(yùn)行代碼"是一個(gè)很方便的功能,可以直接看到代碼的效果,感興趣的朋友不妨參考下,或許對你學(xué)習(xí)js有所幫助,好了花不多說切入正題2013-02-02javascript實(shí)現(xiàn)動態(tài)標(biāo)簽云
JS標(biāo)簽云效果,在鼠標(biāo)的作用下會自動轉(zhuǎn)動,整體上圍繞成一個(gè)圓形,各個(gè)標(biāo)簽之間無需Div代碼,直接文字+鏈接的形式,有多少就顯示多少,JavaScript會自動調(diào)整顯示數(shù)量,讓視覺效果最佳。2015-10-10JavaScript數(shù)據(jù)結(jié)構(gòu)之二叉樹的計(jì)數(shù)算法示例
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)之二叉樹的計(jì)數(shù)算法,結(jié)合具體實(shí)例形式分析了javascript二叉樹記錄更新次數(shù)的原理與操作技巧,需要的朋友可以參考下2017-04-04Js圖片點(diǎn)擊切換輪播實(shí)現(xiàn)代碼
這篇文章主要介紹了Js圖片點(diǎn)擊切換輪播實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07uniapp基礎(chǔ)知識點(diǎn)掌握以及面試題整理
uni-app是一個(gè)使用vue.js開發(fā)所有前端應(yīng)用的框架,開發(fā)者編寫一套代碼,下面這篇文章主要給大家介紹了關(guān)于uniapp基礎(chǔ)知識點(diǎn)掌握以及面試題整理的相關(guān)資料,需要的朋友可以參考下2023-02-02