charts.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:5k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.0.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';
  2. Ext.onReady(function(){
  3.     var store = new Ext.data.JsonStore({
  4.         fields:['name', 'visits', 'views'],
  5.         data: [
  6.             {name:'Jul 07', visits: 245000, views: 3000000},
  7.             {name:'Aug 07', visits: 240000, views: 3500000},
  8.             {name:'Sep 07', visits: 355000, views: 4000000},
  9.             {name:'Oct 07', visits: 375000, views: 4200000},
  10.             {name:'Nov 07', visits: 490000, views: 4500000},
  11.             {name:'Dec 07', visits: 495000, views: 5800000},
  12.             {name:'Jan 08', visits: 520000, views: 6000000},
  13.             {name:'Feb 08', visits: 620000, views: 7500000}
  14.         ]
  15.     });
  16.     // extra extra simple
  17.     new Ext.Panel({
  18.         title: 'ExtJS.com Visits Trend, 2007/2008 (No styling)',
  19.         renderTo: 'container',
  20.         width:500,
  21.         height:300,
  22.         layout:'fit',
  23.         items: {
  24.             xtype: 'linechart',
  25.             store: store,
  26.             xField: 'name',
  27.             yField: 'visits',
  28. listeners: {
  29. itemclick: function(o){
  30. var rec = store.getAt(o.index);
  31. Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
  32. }
  33. }
  34.         }
  35.     });
  36.     // extra simple
  37.     new Ext.Panel({
  38.         iconCls:'chart',
  39.         title: 'ExtJS.com Visits Trend, 2007/2008 (Simple styling)',
  40.         frame:true,
  41.         renderTo: 'container',
  42.         width:500,
  43.         height:300,
  44.         layout:'fit',
  45.         items: {
  46.             xtype: 'linechart',
  47.             store: store,
  48.             url: '../../resources/charts.swf',
  49.             xField: 'name',
  50.             yField: 'visits',
  51.             yAxis: new Ext.chart.NumericAxis({
  52.                 displayName: 'Visits',
  53.                 labelRenderer : Ext.util.Format.numberRenderer('0,0')
  54.             }),
  55.             tipRenderer : function(chart, record){
  56.                 return Ext.util.Format.number(record.data.visits, '0,0') + ' visits in ' + record.data.name;
  57.             }
  58.         }
  59.     });
  60.     // more complex with a custom look
  61.     new Ext.Panel({
  62.         iconCls:'chart',
  63.         title: 'ExtJS.com Visits and Pageviews, 2007/2008 (Full styling)',
  64.         frame:true,
  65.         renderTo: 'container',
  66.         width:500,
  67.         height:300,
  68.         layout:'fit',
  69.         items: {
  70.             xtype: 'columnchart',
  71.             store: store,
  72.             url:'../../resources/charts.swf',
  73.             xField: 'name',
  74.             yAxis: new Ext.chart.NumericAxis({
  75.                 displayName: 'Visits',
  76.                 labelRenderer : Ext.util.Format.numberRenderer('0,0')
  77.             }),
  78.             tipRenderer : function(chart, record, index, series){
  79.                 if(series.yField == 'visits'){
  80.                     return Ext.util.Format.number(record.data.visits, '0,0') + ' visits in ' + record.data.name;
  81.                 }else{
  82.                     return Ext.util.Format.number(record.data.views, '0,0') + ' page views in ' + record.data.name;
  83.                 }
  84.             },
  85.             chartStyle: {
  86.                 padding: 10,
  87.                 animationEnabled: true,
  88.                 font: {
  89.                     name: 'Tahoma',
  90.                     color: 0x444444,
  91.                     size: 11
  92.                 },
  93.                 dataTip: {
  94.                     padding: 5,
  95.                     border: {
  96.                         color: 0x99bbe8,
  97.                         size:1
  98.                     },
  99.                     background: {
  100.                         color: 0xDAE7F6,
  101.                         alpha: .9
  102.                     },
  103.                     font: {
  104.                         name: 'Tahoma',
  105.                         color: 0x15428B,
  106.                         size: 10,
  107.                         bold: true
  108.                     }
  109.                 },
  110.                 xAxis: {
  111.                     color: 0x69aBc8,
  112.                     majorTicks: {color: 0x69aBc8, length: 4},
  113.                     minorTicks: {color: 0x69aBc8, length: 2},
  114.                     majorGridLines: {size: 1, color: 0xeeeeee}
  115.                 },
  116.                 yAxis: {
  117.                     color: 0x69aBc8,
  118.                     majorTicks: {color: 0x69aBc8, length: 4},
  119.                     minorTicks: {color: 0x69aBc8, length: 2},
  120.                     majorGridLines: {size: 1, color: 0xdfe8f6}
  121.                 }
  122.             },
  123.             series: [{
  124.                 type: 'column',
  125.                 displayName: 'Page Views',
  126.                 yField: 'views',
  127.                 style: {
  128.                     image:'bar.gif',
  129.                     mode: 'stretch',
  130.                     color:0x99BBE8
  131.                 }
  132.             },{
  133.                 type:'line',
  134.                 displayName: 'Visits',
  135.                 yField: 'visits',
  136.                 style: {
  137.                     color: 0x15428B
  138.                 }
  139.             }]
  140.         }
  141.     });
  142. });