1.配置參數
{ xtype: 'panel', layout: 'fit', title: '趨勢圖', //bodyStyle: 'background:#ffc; padding:10px;', height: 250, width: 1000, forceFit: true, //frame: true, items: { id: 'XTYXQK_qushitu_chart', xtype: 'chart', //設定圖表類型 //style: 'background:#000', animate: true, //開始載入時是否動畫 shadow: true, //加上陰影 自動建立一個Ext.Shadow,或一個字串表示Ext.Shadow.mode影子的顯示 store: states,//資料對象 legend: { position: 'top', boxStroke: 'border:0px;', labelFont: '11px Helvetica' }, //顯示 柱子類型標題 或時內容的標題 預設為false 若設為true 預設position-bottom //axes :軸 axes: [ { type: 'Numeric', //數字類型軸 position: 'left', //固定位置 fields: ['huoyueyonghushu', 'crmshibaishu'], //Y軸座標資料,會取最大值 label: { //軸上資料文本顯示 比如label: { rotate: { degrees: 315} } 旋轉315° renderer: Ext.util.Format.numberRenderer('0') }, //title: 'Y座標', minimum: 0, //起始點數 預設0 grid: true //顯示背景表格對照 }, { type: 'Category', position: 'bottom', //title: '月份', fields: ['xuhao'], grid: true, label: { //rotate: { degrees: 315 }, renderer: function (lbl) {//這邊是需求 太多了 然後少顯示些X座標軸的值得 var count = Ext.getCmp('XTYXQK_qushitu_chart').store.data.items.length; var num1 = parseInt(count / 12); count % 2 > 0 ? num1++ : ''; return lbl % num1 == 0 ? lbl : ''; } } } ], series: [ //豎條 內容 { type: 'column', axis: 'left', //指定Y軸 是左邊這條 highlight: true, //滑鼠移上去是否高亮顯示 tips: {//柱條上面的tip版 trackMouse: true, //滑鼠觸發 width: 140, height: 28, renderer: function (storeItem, item) {//storeItem該條資料 item(x,y的值) //this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1')); //this.setTitle(item.value[0] + ': ' + item.value[1]); this.setTitle(storeItem.get('riqi') + ': ' + item.value[1]); } }, title: ['活躍使用者數', 'crm失敗使用者數', '提速失敗使用者數', '頻寬不足使用者數'], //柱子的標題 與前面的legend 對應 若沒設 則 欄位名 label: {//柱子上面的文字 display: 'insideEnd', 'text-anchor': 'middle', field: ['huoyueyonghushu', 'crmshibaishu'], renderer: function (lbl) { var count = Ext.getCmp('XTYXQK_qushitu_chart').store.data.items.length; return count <= 12 ? lbl : ''; }, orientation: 'vertical', //顯示方向 color: '#333' }, xField: 'xuhao', yField: ['huoyueyonghushu', 'crmshibaishu'] } ] } }
1.1註解:
圖表的幾大要素:1、座標:上、下、左、右。座標的類型,數字、分類...座標包含需要顯示的座標值,即綁定的欄位座標值的樣式,比如旋轉、字型大小、格式座標的最大值、最小值、是否顯示網格座標旁邊顯示的文字2、圖表:柱狀圖、折線圖、點圖、餅圖、地區圖、盤表圖、雷達圖...表徵圖的類型圖表x、y軸對應的欄位表徵圖上顯示的文字,文字的樣式、位置滑鼠移上去需要顯示的提示資訊3、樣式4、資料axes:用來配置座標,可以配置多個座標。type:配置座標的類型。一般用到的是Numeric、Categoryposition:配置座標的位置,比如:上下左右fields:可以配置多個欄位,用來設定座標顯示的值。其實這個配置和series中的yFiled配置項是沒有關係的label:可以配置文字的顯示方式。預設顯示欄位的值。比如設定label旋轉一定的度數label: {rotate: {degrees: 315}}title:配置座標需要顯示的titlegrid:設定網格的樣式。比如設定網格的透明度、樣式等。grid: { // 設定網格顏色值odd: {opacity: 1,fill: '#ddd',stroke: '#bbb','stroke-width': 1}}minimum:可以配置座標的最小值。當然會有對應的最大值maximum。可以配合使用majorTickSteps(主刻度,配置總共有多少個刻度),minorTickSteps(次刻度,在每個主可短中畫次刻度。比如配置10,則數字沒增加10,會話一個次刻度)series:用來配置圖表type:配置圖表的類型,圖表有很多類型。每個圖表都有各自獨特的配置項axis:相對於哪個座標。因為座標有多個,圖表的高度,總的有個參照。highlight:設定滑鼠移動到圖表上面,是否高亮。不過這個反應很慢。tips:設定滑鼠移動到圖表上時的提示資訊label:設定圖表上顯示的文字。可以設定文字的位置、樣式。但不是每個圖表都有這個配置項。xField:設定x座標綁定的欄位。因為axes設定了座標的值,所以這個欄位綁定的值必須在axes的座標值中。yField:設定y座標綁定的欄位。
2.簡單的一維charts demo 為:
var chartGrid = Ext.create('Ext.grid.Panel',{ fields:['gridYear','gridNum'], columns:[ {header:'年份',dataIndex:'gridYear',width:100}, {header:'申請專利',dataIndex:'gridNum',width:100} ] });
//折線圖 var chartnumber1 = Ext.create('Ext.chart.Chart', { height:400, width:800, animate:true, shadow:true, store:panelStore1, style:'background:#fff', axes:[{//座標 type:'Numeric', dashSize:10,//座標軸前置航條長度 position:'left', fields:['preStatics'], minimum: mini, maximum:maxi, grid: {//奇數行odd : {opacity: 1,//不透明fill: '#FFFF99',//表格內的填充色stroke: '#FF3300',//表格線顏色'stroke-width': 0.5//表格線寬度},//偶數行even : {opacity: 0,//透明stroke: '#6600CC',//表格線顏色'stroke-width': 0.5//表格線寬度}},majorTickSteps : 20,//主區間數minorTickSteps : 3//副區間數 }, { type:"Category",//目錄座標 position:"bottom", fields:['name'], grid:true, label: { rotate: { degrees: 315//x軸 旋轉 座標的字型顯示 :斜體 } } } ], series:[{//序列 type:'line', axis:'left', xField:'name',//橫 yField:"preStatics",//縱抽欄位 highlight: { size: 7, radius: 7 }, style: { opacity: 0.5 }, markerConfig: { type: 'circle', size: 4, radius: 4, 'stroke-width': 0 }, fill: true,//填滿地區 smooth:true, tips: { trackMouse: true, width: 220, height: 60, layout: 'fit', items:[{ xtype:'container', items:[chartGrid] }], renderer: function(storeItem, item) {////storeItem該條資料 item(x,y的值) var storeItem = item.storeItem var gridStore = chartGrid.store; var data = [{ 'gridYear' :storeItem.get('name'), 'gridNum' :storeItem.get('preStatics') }] gridStore.loadData(data) //this.setTitle("年"+storeItem.get('name')+'專利數'+storeItem.get('preStatics')); } } }] })