extjs圖形繪制之餅圖實現(xiàn)方法分析
本文實例講述了extjs圖形繪制之餅圖實現(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的時候不顯示上面的圖例。
4.tips這里是當鼠標放在餅圖上的時候顯示的提示性文字,其中的renderer方法中可設(shè)置提示哪些內(nèi)容。
5.label 設(shè)置餅圖上顯示文字的一些屬性。其中的display屬性決定文字在餅圖中位置,共有‘outside'、‘rotate'兩種方式,前者表示文字顯示在圖表的外邊,后者文字顯示在圖表的里邊。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript運動效果與技巧匯總》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
javascript面向?qū)ο笾L問對象屬性的兩種方式分析
這篇文章主要介紹了javascript面向?qū)ο笾L問對象屬性的兩種方式分析,實例分析了直接訪問對象屬性的方式與數(shù)組訪問方式,需要的朋友可以參考下2015-01-01
javascript在IE下trim函數(shù)無法使用的解決方法
這篇文章主要介紹了javascript在IE下trim函數(shù)無法使用的解決方法,分別敘述了javascript以及jQuery下的解決方案,對于WEB前端javascript設(shè)計人員進行瀏覽器兼容性調(diào)試有不錯的借鑒價值,需要的朋友可以參考下2014-09-09
Document:getElementsByName()使用方法及示例
Document:getElementsByName()想必大家對它并不陌生吧,主要是根據(jù)名稱獲取元素,下面是其具體的使用方法及范例,感興趣的朋友不要錯過2013-10-10
js獲取當前年月日-YYYYmmDD格式的實現(xiàn)代碼
下面小編就為大家?guī)硪黄猨s獲取當前年月日-YYYYmmDD格式的實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06
使用bootstrap typeahead插件實現(xiàn)輸入框自動補全之問題及解決辦法
這篇文章主要介紹了使用bootstrap typeahead插件實現(xiàn)輸入框自動補全之問題及解決辦法的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

