ChartPortlet.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Ext.define('Ext.app.ChartPortlet', {
  2. extend: 'Ext.panel.Panel',
  3. alias: 'widget.chartportlet',
  4. requires: [
  5. 'Ext.data.JsonStore',
  6. 'Ext.chart.theme.Base',
  7. 'Ext.chart.series.Series',
  8. 'Ext.chart.series.Line',
  9. 'Ext.chart.axis.Numeric'
  10. ],
  11. generateData: function(){
  12. var data = [{
  13. name: 0,
  14. djia: 10000,
  15. sp500: 1100
  16. }],
  17. i;
  18. for (i = 1; i < 50; i++) {
  19. data.push({
  20. name: i,
  21. sp500: data[i - 1].sp500 + ((Math.floor(Math.random() * 2) % 2) ? -1 : 1) * Math.floor(Math.random() * 7),
  22. djia: data[i - 1].djia + ((Math.floor(Math.random() * 2) % 2) ? -1 : 1) * Math.floor(Math.random() * 7)
  23. });
  24. }
  25. return data;
  26. },
  27. initComponent: function(){
  28. Ext.apply(this, {
  29. layout: 'fit',
  30. height: 300,
  31. items: {
  32. xtype: 'chart',
  33. animate: false,
  34. shadow: false,
  35. store: Ext.create('Ext.data.JsonStore', {
  36. fields: ['name', 'sp500', 'djia'],
  37. data: this.generateData()
  38. }),
  39. legend: {
  40. position: 'bottom'
  41. },
  42. axes: [{
  43. type: 'Numeric',
  44. position: 'left',
  45. fields: ['djia'],
  46. title: 'Dow Jones Average',
  47. label: {
  48. font: '11px Arial'
  49. }
  50. }, {
  51. type: 'Numeric',
  52. position: 'right',
  53. grid: false,
  54. fields: ['sp500'],
  55. title: 'S&P 500',
  56. label: {
  57. font: '11px Arial'
  58. }
  59. }],
  60. series: [{
  61. type: 'line',
  62. lineWidth: 1,
  63. showMarkers: false,
  64. fill: true,
  65. axis: 'left',
  66. xField: 'name',
  67. yField: 'djia',
  68. style: {
  69. 'stroke-width': 1,
  70. stroke: 'rgb(148, 174, 10)'
  71. }
  72. }, {
  73. type: 'line',
  74. lineWidth: 1,
  75. showMarkers: false,
  76. axis: 'right',
  77. xField: 'name',
  78. yField: 'sp500',
  79. style: {
  80. 'stroke-width': 1,
  81. stroke: 'rgb(17, 95, 166)'
  82. }
  83. }]
  84. }
  85. });
  86. this.callParent(arguments);
  87. }
  88. });