
# Index.js规范
Index.js文件是组件的主入口文件，该文件提供了一个示例供您参考，并介绍了index.js文件中常用的组件生命周期或相关函数。
表1组件方法 
| 函数                                        | 说明                                                                                                                                                                                                                                                                                                  |
|:---|:---|
| refresh()                                 | 默认渲染方法，当组件初始化和重绘时被调用。 （自定义实现）                                                                                                                                                                                                                                        |
| resize()                                  | 缩放，当组件被拖拽、缩放时被调用。                                                                                                                                                                                                                                                                                   |
| loadData()                                | 更新组件数据，当组件加载数据时调用。 （自定义实现）                                                                                                                                                                                                                                              |
| dispatch(String: eventType, object: data) | 可选方法，触发组件交互事件。如果该组件支持事件交互，需用户自定义实现该方法，并且此方法需要在gui.json中配置组件交互事件(events)。 - eventType：事件名称。  - data：事件触发时传递的数据。   |
| getRelation()                             | 获取组件数据配置映射字段。                                                                                                                                                                                                                                                                                       |
   
Index.js文件示例如下：
```
import gui from './gui.json';
import './index.less';
//global： echarts jQuery
class App extends BaseChart {
  constructor(props = {}) {
    super(props);      
    Object.assign(props);     
    this.chart = echarts.init(this.el);  
  }
  refresh() {
    this.loadData();   
  }
  loadData() {
    let option = this.getOption();      
    if (option) {
      this.chart.setOption(option, true);      
    }   
  }
  resize() {
    this.chart.resize();   
  }
  getOption() {
    let styledata = this.config.styledata,          
        relation = this.getRelation();      
    let yData = [], data = [];      
    this.data.forEach(item => {        
      yData.push(item[relation.x]);         
      data.push(item[relation.y]);      
    });      
    return {
      backgroundColor: '222',         
      grid: {
       top: '20',            
       left: '20',            
       right: '20',            
       bottom: '20',            
       containLabel: true         
      },         
      yAxis: [{
       type: 'category',            
       data: yData,            
       inverse: true,           
       axisTick: {
         show: false            
       },            
       axisLabel: {
         margin: 10,               
         textStyle: {
           fontFamily: styledata['font'],                  
           fontSize: 24,                  
           color: '#fff'               
         }            
       },            
       axisLine: {
         show: false            
       }         
      }],         
      xAxis: [{
        type: 'value',            
        axisLabel: {
          show: false            
        },            
        axisLine: {
          show: false            
        },            
        splitLine: {
          show: false            
        }         
      }],         
      series: [{
        type: 'bar',            
        barWidth: 14,            
        data,            
        label: {
          normal: {
            show: true,                  
            position: 'insideBottomRight',                  
            formatter: '{c}%',                  
            distance: 0,                  
            offset: [30, -20],                  
            color: '#fff',                  
            fontSize: 16,                  
            padding: [5, 15, 10, 15]             
          }            
        },            
        itemStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
              offset: 0,                     
              color: '#57eabf'                  
            }, {
              offset: 1,                     
              color: '#2563f9'                  
            }], false),                  
            barBorderRadius: 14               
           }            
         }         
      }, {
        type: "bar",            
        barWidth: 14,            
        xAxisIndex: 0,            
        barGap: "-100%",            
        data: [120, 120],            
        itemStyle: { 
          normal: {
            color: "#444a58",                  
            barBorderRadius: 14               
          }            
        },            
        zlevel: -1         
     }]      
    };  
 }
}
App.gui = gui;export default App;
```
