热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ExtJS如何将单击事件添加到饼图块中。-ExtJSHowtoaddaclickeventtoPieChartpieces

IhavecreatedaPiechartusingthePiechartexampleinsenchaExtJSwebsite,Iwantedtoaddac

I have created a Pie chart using the Pie chart example in sencha ExtJS website , I wanted to add a click event to the each Pie slice so that i get handle to the contextual data on that slice. I was able to add a click listener to the Pie but not sure how to get the data on the slice.

我使用sencha ExtJS网站的饼图示例创建了一个饼图,我想在每个饼图中添加一个点击事件,这样我就可以处理该切片上的上下文数据。我可以向饼图添加一个单击侦听器,但不确定如何获取切片上的数据。

Below is the ExtJS code.

下面是ExtJS代码。

Ext.onReady(function(){
var store = Ext.create('Ext.data.JsonStore', {
    fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5'],
    data: [{
        'name': 'January',
        'data1': 10
    }, {
        'name': 'February',
        'data1': 7
    }, {
        'name': 'March',
        'data1': 5
    }, {
        'name': 'April',
        'data1': 2
    }, {
        'name': 'May',
        'data1': 27
    }]
});

Ext.create('Ext.chart.Chart', {
    renderTo: Ext.getBody(),
    width: 800,
    height: 600,
    animate: true,
    store: store,
    theme: 'Base:gradients',
    legend: { // Pie Chart Legend Position
        position: 'right'
    },
    series: [{
        type: 'pie',
        field: 'data1',
        showInLegend: true,
        tips: {
            trackMouse: true,
            width: 140,
            height: 28,
            renderer: function(storeItem, item){
                //calculate and display percentage on hover
                var total = 0;
                store.each(function(rec){
                    total += rec.get('data1');
                });
                this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data1') / total * 100) + '%');
            }
        },
        highlight: {
            segment: {
                margin: 5
            }
        },
        label: {
            field: 'name',
            display: 'rotate',
            contrast: true,
            font: '18px Arial'
        },
        listeners: {//This Doesnt Work :(
            itemclick: function(o){
                alert('clicked at : ' + o);
            }
        }

    }],
    listeners: { //This Event handler works but I am not sure how to figure how which slice i have clicked ..................................
        click: {

            element: store, //bind to the underlying el property on the panel
            fn: function(o, a){

                alert('clicked' + o + a + this);
            }
        }

    }

});

});

Kindly help.

请帮助。

Regards, Lalit

问候,拉

2 个解决方案

#1


11  

Here is how you get data of the clicked slice. The series class supports listeners via the Observable syntax and they are:

下面是如何获取单击切片的数据。系列类通过可观察的语法支持监听器,它们是:

  1. itemmouseup When the user interacts with a marker.
  2. 当用户与标记交互时,itemmouseup。
  3. itemmousedown When the user interacts with a marker.
  4. 当用户与标记交互时,itemmousedown。
  5. itemmousemove When the user iteracts with a marker.
  6. 当用户使用标记进行迭代时,itemmousemoemove。
  7. afterrender Will be triggered when the animation ends or when the series has been rendered completely.
  8. 当动画结束或整个系列渲染完成时,将触发afterrender。

I will make use of the itemmousedown event to capture the clicked slice. Here is my listener method:

我将使用itemmousedown事件来捕获被单击的切片。下面是我的聆听者方法:

series: [{
        .
    .
    .
    listeners:{
        itemmousedown : function(obj) {
        alert(obj.storeItem.data['name'] + ' &' + obj.storeItem.data['data1']);
    }
    }
    .
}]

Note that I have placed my listener inside the series and not the chart! Now, the obj variable holds lot of information. For each series, the property to get data will differ. So, you will have to carefully inspect the object using firebug or some other developer tool.

注意,我把我的听众放在了这个系列中,而不是图表中!obj变量包含很多信息。对于每个系列,获取数据的属性都不同。因此,您必须使用firebug或其他开发人员工具仔细检查对象。

Now, in case of Piecharts, you can get the slice information by using the obj:

对于压电片,你可以用obj来获取切片信息:

obj.storeItem.data['your-series-variable-name']

Here is the obj from firebug.. enter image description here

这是firebug的obj。

#2


0  

I'm using a more selective approach, because I needed to add some custom logic in order to implement drag-and-drop for our charts. So after the chart definition I just add the following:

我使用了一种更有选择性的方法,因为我需要添加一些自定义逻辑,以便为我们的图表实现拖放。所以在图表定义之后,我添加了以下内容:

// Add drag-and-drop listeners to the sprites
var surface = chart.surface;
var items = surface.items.items;
for (var i = 0, ln = items.length; i 

Cheers! Frank

干杯!弗兰克


推荐阅读
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 计算机存储系统的层次结构及其优势
    本文介绍了计算机存储系统的层次结构,包括高速缓存、主存储器和辅助存储器三个层次。通过分层存储数据可以提高程序的执行效率。计算机存储系统的层次结构将各种不同存储容量、存取速度和价格的存储器有机组合成整体,形成可寻址存储空间比主存储器空间大得多的存储整体。由于辅助存储器容量大、价格低,使得整体存储系统的平均价格降低。同时,高速缓存的存取速度可以和CPU的工作速度相匹配,进一步提高程序执行效率。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文详细介绍了Spring的JdbcTemplate的使用方法,包括执行存储过程、存储函数的call()方法,执行任何SQL语句的execute()方法,单个更新和批量更新的update()和batchUpdate()方法,以及单查和列表查询的query()和queryForXXX()方法。提供了经过测试的API供使用。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
author-avatar
Fabio_Ho_275
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有