chartsgridextjs4highlight

Highlighting Bars in a chart when clicking on the related data in a grid with ExtJS 4


I have two objects on my screen, a grid and a chart being populated by the same store. What I need to do is highlight the Column on the chart related to the item I clicked in the grid.

In the function I've figured half way to do it using Ext.getCmp('chart').series.get(0). But don't know what to do to get to each item of the series and highlight it, as the getItemForPoint(x,y) keeps returning null values...

Thanks a lot, code below:

// Code for my grid
{
 columnWidth: .25
 ,xtype: 'grid'
 ,hideHeaders: true
 ,border: true
 ,styke: 'padding-top: 60px;'
 ,height: 360
 ,store: participation
 ,columns: [{
      dataIndex: 'ID'
      ,width: 24
 },{
      dataIndex: 'Supplier'
      ,width: 204
}]
 ,listeners: {
      select: function() {
           // function to highlight the column on my chart
      }
 }
}

// Code for my chart
{
 border: false
 ,layout: 'column'
 ,items: [{
    columnWidth: .75
    ,xtype: 'chart'
    ,animate: true
    ,height: 432
    ,shadow: false
    ,id: 'chart'
    ,store: participation
    ,axes: [{
        type: 'Numeric'
        ,position: 'left'
        ,grid: true
        ,fields: 'Participation'
        ,title: 'Share'
        ,label: {
            renderer: Ext.util.Format.numberRenderer('0.00'+"%")
        }
    },{
        type: 'Category'
        ,position: 'bottom'
        ,fields: 'ID'
    }]
    ,series: [{
        type: 'column'
        ,axis: 'left'
        ,highlight: 'true'
        ,xField: 'ID'
        ,yField: 'Participation'
        ,tips: {
            trackMouse: true
            ,width: 312
            ,maxWidth: 360
            ,height: 36
            ,constrainPosition: true
            ,renderer: function(storeItem, item) {
                this.setTitle('Supplier: ' + storeItem.get('Supplier')+'<br/>'+'Share: ' + Ext.util.Format.number(storeItem.get('Share'),"0.00")+'%');
            }
        }
        ,style: {
            lineWidth: 1
            ,stroke: '#666'
        }
    }]
  }
 }

Solution

  • Have a look at the Dynamic Form, Grid and Charts in ExtJS examples. The example demos exactly what you are trying to achieve. Refer to the listeners attached to the chart and gridPanel (selectionchange event etc).