Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:38:31+00:00 2026-06-06T12:38:31+00:00

EXTJS 4 – I am trying to customize the renderer function for the ‘series’

  • 0

EXTJS 4 – I am trying to customize the renderer function for the ‘series’ in StackedBarChart. I want to conditionally color the bars.

renderer: function(sprite, record, curAttr, index, store) {
                        return Ext.apply(curAttr, {
                              fill: color
                        });
                        return curAttr;
},

My Question is, how to find out which element its currently rendering. I want to give white color to the first element of each record in my data store/series.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:38:32+00:00Added an answer on June 6, 2026 at 12:38 pm

    I found a way to detect exactly which element is currently being rendered. First, you’ll need the following override, which addresses several issues with the renderer parameters. It shouldn’t affect the normal bar charts, but I haven’t tested them.

    Ext.override(Ext.chart.series.Bar,{
        drawSeries: function() {
            var me = this,
                chart = me.chart,
                store = chart.getChartStore(),
                surface = chart.surface,
                animate = chart.animate,
                stacked = me.stacked,
                column = me.column,
                enableShadows = chart.shadow,
                shadowGroups = me.shadowGroups,
                shadowGroupsLn = shadowGroups.length,
                group = me.group,
                seriesStyle = me.seriesStyle,
                items, ln, i, j, baseAttrs, sprite, rendererAttributes, shadowIndex, shadowGroup,
                bounds, endSeriesStyle, barAttr, attrs, anim;
    
            // ---- start edit ----
            var currentCol, currentStoreIndex;
            // ---- end edit ----
    
    
            if (!store || !store.getCount()) {
                return;
            }
    
            //fill colors are taken from the colors array.
            delete seriesStyle.fill;
            endSeriesStyle = Ext.apply(seriesStyle, this.style);
            me.unHighlightItem();
            me.cleanHighlights();
    
            me.getPaths();
            bounds = me.bounds;
            items = me.items;
    
            baseAttrs = column ? {
                y: bounds.zero,
                height: 0
            } : {
                x: bounds.zero,
                width: 0
            };
            ln = items.length;
            // Create new or reuse sprites and animate/display
            for (i = 0; i < ln; i++) {
                sprite = group.getAt(i);
                barAttr = items[i].attr;
    
                if (enableShadows) {
                    items[i].shadows = me.renderShadows(i, barAttr, baseAttrs, bounds);
                }
    
                // ---- start edit ----
                if (stacked && items[i].storeItem.index != currentStoreIndex) {
                  //console.log("i: %o, barsLen: %o, j: %o, items[i]: %o",i,bounds.barsLen,i / bounds.barsLen,items[i]);
                  currentStoreIndex = items[i].storeItem.index;
                  currentCol = 0;
                }
                else {
                  ++currentCol;
                }
                // ---- end edit ----
    
                // Create a new sprite if needed (no height)
                if (!sprite) {
                    attrs = Ext.apply({}, baseAttrs, barAttr);
                    attrs = Ext.apply(attrs, endSeriesStyle || {});
                    sprite = surface.add(Ext.apply({}, {
                        type: 'rect',
                        group: group
                    }, attrs));
                }
                if (animate) {
                    // ---- start edit ----
                    rendererAttributes = me.renderer(sprite, items[i].storeItem, barAttr, (stacked? currentStoreIndex : i), store, (stacked? currentCol : undefined));
                    // ---- end edit ----
                    sprite._to = rendererAttributes;
                    anim = me.onAnimate(sprite, { to: Ext.apply(rendererAttributes, endSeriesStyle) });
                    if (enableShadows && stacked && (i % bounds.barsLen === 0)) {
                        j = i / bounds.barsLen;
                        for (shadowIndex = 0; shadowIndex < shadowGroupsLn; shadowIndex++) {
                            anim.on('afteranimate', function() {
                                this.show(true);
                            }, shadowGroups[shadowIndex].getAt(j));
                        }
                    }
                }
                else {
                    // ---- start edit ----
                    rendererAttributes = me.renderer(sprite, items[i].storeItem, Ext.apply(barAttr, { hidden: false }), (stacked? currentStoreIndex : i), store, (stacked? currentCol : undefined));
                    // ---- end edit ----
                    sprite.setAttributes(Ext.apply(rendererAttributes, endSeriesStyle), true);
                }
                items[i].sprite = sprite;
            }
    
            // Hide unused sprites
            ln = group.getCount();
            for (j = i; j < ln; j++) {
                group.getAt(j).hide(true);
            }
            // Hide unused shadows
            if (enableShadows) {
                for (shadowIndex = 0; shadowIndex < shadowGroupsLn; shadowIndex++) {
                    shadowGroup = shadowGroups[shadowIndex];
                    ln = shadowGroup.getCount();
                    for (j = i; j < ln; j++) {
                        shadowGroup.getAt(j).hide(true);
                    }
                }
            }
            me.renderLabels();
        }
    });
    

    Here’s the change list for renderer():

    • The second parameter is now mapped to the correct store item
    • The fourth parameter is now the store index number instead of the internal item number (worthless otherwise IMO)
    • Added a sixth parameter that tells the current segment index within the record, not counting other properties in the record that don’t belong to the axis.
      Example: for a record that looks like {name: 'metric': segment1: 12, segment2: 22}, the index for segment1 will be 0 instead of 1, because the first item in the record does not belong to its axis (it’s the category name)

    So, to answer your question, now you can use the renderer like so:

    renderer: function(sprite, record, attr, storeIndex, store, col) {
        // set the color to white for the first item in every record
        return (col == 0)? Ext.apply(attr, { fill: '#fff' }) : attr;
    }
    

    If you want to set the color for a named item, you may also do it like this:

    // let's say that every record looks like this:
    // {name: 'metric one', user1: 23, user2: 50, user3: 10}
    
    renderer: function(sprite, record, attr, storeIndex, store, col) {
        // retrieve the segment property name from the record using its numeric index.
        // remember that 'col' doesn't take into account other fields that don't
        // belong to the axis, so in this case we have to add 1 to the index
        var uid = Ext.Object.getAt(record.data, col+1)[0];
    
        // set the color to red for 'user2'
        return (uid == 'user2')? Ext.apply(attr, { fill: '#f00' }) : attr;
    }
    

    For that last one, you’ll need this function, which allows you to retrieve a property from an object using a numeric index:

    /**
     * Returns the key and its value at the idx position
     * @return {Array} Array containing [key, value] or null
     */
    Ext.Object.getAt = function(obj, idx) {
        var keys = Ext.Object.getKeys(obj);
        if (idx < keys.length) {
            return [keys[idx],obj[keys[idx]]];
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Session expires frequently in extjs load() function. When i'm trying to load data into
ExtJS Charts, I am using an Ext column chart and I want to implement
Using ExtJs. I'm trying to design a main which is divided into three sub
I am new to ExtJS 4 and am trying to implement a simple application
in ExtJS 4 I have an EditorGrid with Grouping feature. I want to make
I am using extjs 4.0.7. I want to disabled tab and Enter key event
ExtJS : I have a button where I want to associate a menu. I
For extjs combo, here is the behavior I am trying to udnerstand. When we
ExtJS has Ext.each() function, but is there a map() also hidden somewhere? I have
in ExtJS 3.x grid panels that used a remote datastore and paging bars had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.