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,// 是否支持動(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'兩種方式,前者表示文字顯示在圖表的外邊,后者文字顯示在圖表的里邊。
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript運(yùn)動(dòng)效果與技巧匯總》、《JavaScript動(dòng)畫(huà)特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- JavaScript使用百度ECharts插件繪制餅圖操作示例
- JS+canvas動(dòng)態(tài)繪制餅圖的方法示例
- 讀取數(shù)據(jù)庫(kù)的數(shù)據(jù)并整合成3D餅圖在jsp中顯示詳解
- Javascript highcharts 餅圖顯示數(shù)量和百分比實(shí)例代碼
- html+js+highcharts繪制圓餅圖表的簡(jiǎn)單實(shí)例
- 使用js畫(huà)圖之餅圖
- javaScript矢量圖表庫(kù)-gRaphael幾行代碼實(shí)現(xiàn)精美的條形圖/餅圖/點(diǎn)圖/曲線圖
- 輕松使用JSP生成餅圖
- JavaScript 繪制餅圖的示例
相關(guān)文章
javascript面向?qū)ο笾L問(wèn)對(duì)象屬性的兩種方式分析
這篇文章主要介紹了javascript面向?qū)ο笾L問(wèn)對(duì)象屬性的兩種方式分析,實(shí)例分析了直接訪問(wèn)對(duì)象屬性的方式與數(shù)組訪問(wèn)方式,需要的朋友可以參考下2015-01-01
javascript在IE下trim函數(shù)無(wú)法使用的解決方法
這篇文章主要介紹了javascript在IE下trim函數(shù)無(wú)法使用的解決方法,分別敘述了javascript以及jQuery下的解決方案,對(duì)于WEB前端javascript設(shè)計(jì)人員進(jìn)行瀏覽器兼容性調(diào)試有不錯(cuò)的借鑒價(jià)值,需要的朋友可以參考下2014-09-09
Document:getElementsByName()使用方法及示例
Document:getElementsByName()想必大家對(duì)它并不陌生吧,主要是根據(jù)名稱(chēng)獲取元素,下面是其具體的使用方法及范例,感興趣的朋友不要錯(cuò)過(guò)2013-10-10
js canvas實(shí)現(xiàn)簡(jiǎn)單的圖像擴(kuò)散效果
這篇文章主要為大家詳細(xì)介紹了js canvas實(shí)現(xiàn)簡(jiǎn)單的圖像擴(kuò)散效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
js獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇js獲取當(dāng)前年月日-YYYYmmDD格式的實(shí)現(xiàn)代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
使用bootstrap typeahead插件實(shí)現(xiàn)輸入框自動(dòng)補(bǔ)全之問(wèn)題及解決辦法
這篇文章主要介紹了使用bootstrap typeahead插件實(shí)現(xiàn)輸入框自動(dòng)補(bǔ)全之問(wèn)題及解決辦法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
JS創(chuàng)建自定義表格具體實(shí)現(xiàn)
創(chuàng)建自定義表格的方法有很多,本文為大家介紹下使用js是如何創(chuàng)建的,感興趣的朋友可以參考下2014-02-02

