Ext4.1 chart的使用,Ext4.1chart使用

來源:互聯網
上載者:User

Ext4.1 chart的使用,Ext4.1chart使用
var reportsPanel = Ext.create('Ext.panel.Panel', {
id:'reportsPanel',
   layout: 'fit',
   tbar: [{
       text: '儲存報表',
       handler: function() {
           Ext.MessageBox.confirm('確認下載', '您想儲存報表到圖片', function(choice){
               if(choice == 'yes'){
                   chart.save({
                       type: 'image/png'
                   });
               }
           });
       }
   },'-',{
    text: '分別顯示',
    menu:[{
text:'整年'
},'-',{
text:'季度'
},'-',{
text:'月份'
}]
   }],
   items:chart
});


var store1 = Ext.create('Ext.data.Store',{//JsonStore  
    fields:['date', 'price', 'sales'], //日期、單價、銷售額
    data: [
{date  :'1/1', price : 5, sales : 140}, 
{date  :'1/2', price : 29, sales : 135},
{date  :'1/3', price : 18, sales : 125},  
{date  :'1/4', price : 21, sales : 130},  
{date  :'1/5', price : 23,sales : 124},  
{date  :'1/6', price : 16, sales : 137},
{date  :'1/7', price : 13, sales : 90}, 
{date  :'1/8', price : 19, sales : 128},
{date  :'1/9', price : 21, sales : 159},  
{date  :'1/10', price : 40, sales : 151},  
{date  :'1/11', price : 30,sales : 89},  
{date  :'1/12', price : 19, sales : 130},
{date  :'1/13', price : 12, sales : 133}, 
{date  :'1/14', price : 3, sales : 96},
{date  :'1/15', price : 23, sales : 142},  
{date  :'1/16', price : 12, sales : 81},  
{date  :'1/17', price : 19,sales : 94},  
{date  :'1/18', price : 11, sales : 119},
{date  :'1/19', price : 22, sales : 120}, 
{date  :'1/20', price : 13, sales : 121},
{date  :'1/21', price : 35, sales : 135},  
{date  :'1/22', price : 12, sales : 111},  
{date  :'1/23', price : 36,sales : 117},  
{date  :'1/24', price : 19, sales : 117},
{date  :'1/26', price : 17, sales : 95}, 
{date  :'1/27', price : 38, sales : 135},
{date  :'1/28', price : 12, sales : 122},  
{date  :'1/29', price : 45, sales : 130},  
{date  :'1/30', price : 46,sales : 99},  
{date  :'1/31', price : 7, sales : 130}
    ]  
}); 
var chart = Ext.create('Ext.chart.Chart', {
    id: 'chartCmp',
    xtype: 'chart',
    style: 'background:#fff',
    theme: 'Category6',
    animate: true,
//    shadow: true,
    maximizable: true,  
    store: store1,
    axes: [{
        type: 'Numeric',
        position: 'left',
        fields: ['date','price', 'sales'],
        label: {
            renderer: Ext.util.Format.numberRenderer('0,0')
        },
        title: '價格:百噸',
        grid: true,
        minimum: 0
    }, {
        type: 'Category',
        position: 'bottom',
        fields: ['date'],
        title: '日期'
    }],
    series: [{//油品,單價價格浮動
        type: 'column',
        axis: 'left',
        highlight: true,
        tips: {
          trackMouse: true,
          width: 140,
          height: 28,
          renderer: function(storeItem, item) {
            this.setTitle(storeItem.get('date') + ': ' + storeItem.get('price')+'%');
          }
        },
        label: {
          display: 'insideEnd',
          'text-anchor': 'middle',
            field: 'date',
            renderer: Ext.util.Format.numberRenderer('0'),
            orientation: 'vertical',
            color: '#333'
        },
        xField: 'date',
        yField: 'price'
    },{//銷售額
    type: 'line',
        axis: 'left',
        tips: {
            trackMouse: true,
            width: 140,
            height: 28,
            renderer: function(storeItem, item) {
              this.setTitle(storeItem.get('date') + ': ' + storeItem.get('price')+'%');
            }
        },  
        smooth: true,
        markerConfig: {// 由Ext.Draw.Sprite配置項決定   
            type: 'circle',  
            size: 4,  
            radius: 4,  
            fill: '#00f',  
            'stroke-width': 0  
        },  
//        fill: true,
//        fillOpacity: 0.5,
        xField: 'date',
        yField: 'sales'
    }]

});


該圖表顯示的是不同月份不同單價的銷售業績


圖表的幾大要素:

1、座標:上、下、左、右。

座標的類型,數字、分類...

座標包含需要顯示的座標值,即綁定的欄位

座標值的樣式,比如旋轉、字型大小、格式

座標的最大值、最小值、是否顯示網格

座標旁邊顯示的文字

2、圖表:柱狀圖、折線圖、點圖、餅圖、地區圖、盤表圖、雷達圖...

表徵圖的類型

圖表x、y軸對應的欄位

表徵圖上顯示的文字,文字的樣式、位置

滑鼠移上去需要顯示的提示資訊

3、樣式

4、資料

屬性介紹:

axes:用來配置座標,可以配置多個座標。

type:配置座標的類型。一般用到的是Numeric、Category

position:配置座標的位置,比如:上下左右

fields:可以配置多個欄位,用來設定座標顯示的值。其實這個配置和series中的yFiled配置項是沒有關係的

label:可以配置文字的顯示方式。預設顯示欄位的值。比如設定label旋轉一定的度數

              label: {
                    rotate: {
                        degrees: 315
                    }
                }

title:配置座標需要顯示的title

grid:設定網格的樣式。比如設定網格的透明度、樣式等。

           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座標綁定的欄位。




ext4 chart怎添加標題的點擊事件

如果是ExtJS,如果在幾小時內找不到合適的方法。你就從原生JS的角度去加吧絕對可以的,那個id或者class命名覺得可以用select找出來。
 
Extjs41對於 Chart時間軸的問題?

type: 'Time', 改為 type : 'Category'
去掉
groupBy: 'hour',
dateFormat: 'ga'
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.