Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs4: How to add custom listener & tooltip to a chart?

Tags:

extjs

extjs4

I am creating a radar chart to display data and it works just fine. However, the title(s) that appear in the legend can be extremely long. Right now I have it showing a shortened version of the title in the legend, but I would like it so when the user does a mouseover on a legend title, a tooltip or some time of bubble pops up that shows the full title/label. From what I see in the API docs, I can see you can add a listener to the entire chart, but not just on the legend titles.

You can however click on a legend item to make the data show/hide, so there is some type of listening functionality. Any ideas how I can add a custom mouseover listener to the legend of the following radar chart?

Ext.define("COM.view.portlet.RadarChart", {
extend  : "Ext.panel.Panel",
alias   : "widget.myradarchart",
requires: ["Ext.chart.theme.Base", "Ext.chart.series.Series"],

initComponent: function () {
    //@fixme: Why is the first radar not show x-axis lines?
    Ext.apply(this, {
        layout: "fit",
        width: 600,
        height: 300,
        items: {
            xtype: 'chart',
            style: 'background:#fff',
            theme: 'Category2',
            insetPadding: 20,
            animate: true,
            store: 'Seoradar',
            legend: {
                position: "bottom"
                //ADDING LISTENERS HERE DOESN'T WORK
            },
            axes: [{
                type: "Radial",
                position: "radial",
                maximum: 100,
                label: {
                    font: "11px Arial",
                    display : "none"
                }
            }],
            series: [{
                showInLegend    : true,
                showMarkers     : true,
                markerConfig: {
                    radius  : 2,
                    size    : 2
                },
                type    : 'radar',
                xField  : 'name',
                yField  : 'site0',
                style: {
                    opacity: 0.4
                }
            },{
                showInLegend    : true,
                showMarkers     : true,
                type            : 'radar',
                xField          : 'name',
                yField          : 'site1',
                style: {
                    opacity: 0.4
                }
            }]
        }
    });
    this.callParent(arguments);
}

});

like image 462
Nathan Avatar asked Nov 13 '22 22:11

Nathan


1 Answers

If you want to get this event out of the Chart you can push it up from the series to the chart by saying:

       {
            'type' : 'line',
            'axis' : 'left',
            'highlight' : true,
            'listeners' : {
                'itemmousedown' : function(event){
                    event.series.chart.fireEvent('itemmousedown', event);
                }
            }
       }

so in your controller you can say:

this.control({
    'chart' : {
         'itemmousedown' : function(event){
             //do your stuff here
         }
    }
});

!!ATTENTION!!

I noticed that those mousedown events are executed in another contaxt than the UI Context, so i was unable to show a Window in the Context of the Event Handler. I had to getr around this by using setTimeout and saving the eventobject somewhere. I think maybe this is because on some browser SVG Rendering is Hardware accelerated.

like image 169
martyglaubitz Avatar answered Dec 05 '22 13:12

martyglaubitz