2011-09-19 62 views
0

我怎么能改变标签上的精灵?我发现系列内我可以有以下,我可以改变渲染,但问题是,我也需要相应的商品。Extjs改变标签在图表(酒吧,派...)

label: { 
    display: 'insideEnd', 
    field: 'litres', 
    renderer: function(n) { 
    return n; 
    }, 
    orientation: 'horizontal', 
    color: '#333', 
    'text-anchor': 'middle' 
} 

我还发现here有两个功能:onCreateLabelonPlaceLabel,但我并没有发现使用它们的方式。

任何帮助?

回答

1

onCreateLabelonPlaceLabel系列配置被使用。你必须做这样的事情:

series: [{ 
     // ... 
     label: { 
       field: 'data1', 
       renderer: function(val) { 
         return val; 
       } 
     }, 
     onCreateLabel: function(storeItem, item, i, display) { 
       var me = this, 
         group = me.labelsGroup, 
         config = me.label, 
         bbox = me.bbox, 
         endLabelStyle = Ext.apply(config, me.seriesLabelStyle); 

       return me.chart.surface.add(Ext.apply({ 
         'type': 'text', 
         'text-anchor': 'middle', 
         'group': group, 
         'x': item.point[0], 
         'y': bbox.y + bbox.height/2 
       }, endLabelStyle || {})); 
     }, 
     onPlaceLabel: function(label, storeItem, item, i, display, animate, index) { 
     var me = this, 
      chart = me.chart, 
      resizing = chart.resizing, 
      config = me.label, 
      format = config.renderer, 
      field = config.field, 
      bbox = me.bbox, 
      x = item.point[0], 
      y = item.point[1], 
      bb, width, height; 

     label.setAttributes({ 
      text: format(storeItem.get(field[index])), 
      hidden: true 
     }, true); 

     bb = label.getBBox(); 
     width = bb.width/2; 
     height = bb.height/2; 

     x = x - width < bbox.x? bbox.x + width : x; 
     x = (x + width > bbox.x + bbox.width) ? (x - (x + width - bbox.x - bbox.width)) : x; 
     y = y - height < bbox.y? bbox.y + height : y; 
     y = (y + height > bbox.y + bbox.height) ? (y - (y + height - bbox.y - bbox.height)) : y; 

     if (me.chart.animate && !me.chart.resizing) { 
      label.show(true); 
      me.onAnimate(label, { 
       to: { 
        x: x, 
        y: y 
       } 
      }); 
     } else { 
      label.setAttributes({ 
       x: x, 
       y: y 
      }, true); 
      if (resizing) { 
       me.animation.on('afteranimate', function() { 
        label.show(true); 
       }); 
      } else { 
       label.show(true); 
      } 
     } 
    } 
     // ... 
} 

复制和粘贴onCreateLabel,并从上面的代码(或ExtJS的源)onPlaceLabel然后改变他们你想要的方式。

+0

是不是有另一种方法来调用重写的方法,而不是将整个东西复制到应用程序中? – Geronimo