Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 5 Chart Legend Issue

I am trying to add a legend to my extjs 5 charts and it doesn't appear to work. Is this a bug or am I doing something wrong?

legend: {  
    docked: 'top',
    style: {
         borderColor: 'red',
         borderStyle: 'solid'
    }
}
like image 836
Niederee Avatar asked Jul 29 '14 13:07

Niederee


2 Answers

I had been working on this same issue for a while - and finally submitted a Sencha Bug Report:

http://www.sencha.com/forum/showthread.php?289279-Sencha-5-Charts-Broken-Legend

Long story short, there's "supposedly" a fix in the next EXTjs rollout. Unfortunately, that doesn't help us now...

You can however, create a tpl for the legend - but my tpl isn't quite as robust as the native extjs legend. It will still show/hide the series, but doesn't mask the series in the legend. I'm still refining the TPL and will post an update as I get one working.

legend: {
        docked: 'top',
        border: 0,
        style: { borderColor: 'red' },
        tpl: [            
            '<tpl for=".">',                
                '<div class="myLegendItem" style="float:left;margin:5px;padding:0px;cursor:pointer;">',
                      '<div class="" style="float:left;margin:2px;width:10px;height: 10px; background:{mark};opacity:.6"></div><div style="float:left;">{name}</div>',                                      
                '</div>',                    
            '</tpl>'                
        ],
        itemSelector: '.myLegendItem'
},
like image 183
Josh Avatar answered Oct 16 '22 05:10

Josh


To mask inactive series in the legend, use a ternary operator to check for values.disabled

<div class="x-legend-container">
    <tpl for=".">
        <div class="x-legend-item {[ values.disabled ? Ext.baseCSSPrefix + 'legend-inactive' : '' ]}">
            <span class="x-legend-item-marker" style="background:{mark};float:left;width:10px;height:10px;"></span>
            <span style="float:left;margin-left:4px;">{name}</span>
        </div>
    </tpl>
</div>

Also if needed add a css class for

x-legend-inactive{
   opacity: 0.5;
}
like image 37
walkerizer Avatar answered Oct 16 '22 06:10

walkerizer