ZP's ExtJS study notes (iv)--Simple use of charts (chart click events)

Source: Internet
Author: User

This is a relatively simple to do, is a message to read the presentation of the situation.

It is the pie.js of the chart in example.

Post the modified pie.js:

Ext.require (' ext.chart.* '); Ext.require ([' Ext.layout.container.Fit ', ' Ext.window.MessageBox ']); Ext.onready (function () {    //Store1.loaddata (Generatedata (6));    varDonut =false, Chart= Ext.create (' Ext.chart.Chart ', {xtype:' Chart ', animate:true, ID:' Domid ', Store:store1, shadow:true, Legend: {position:' Right '}, Insetpadding:60, Theme:' Base:gradients ',            /*listeners: {click: {element:Ext.get (' Domid '),//bind to the underlying El Propert                        Y on the panel fn:function (o) {//alert (o.index);                        var items = chart.series.get (0). items, I;                    Alert (items[1].storeitem.get (' name ')); }                }            },*/series: [{type:' Pie ', field:' Data1 ', Showinlegend:true, Donut:donut, listeners: {itemclick:function(o) {if(O.index = = 1){                            varNoreadstore = ext.create (' Ext.data.Store '), {fields: [' id ', ' name '], Proxy: {type:' Ajax ', API: {read:‘.. /mail/getnoreadmember.dhtml '}, Reader: { Type:' JSON ', Root:' Members '                                    }                                }                            });                            Noreadstore.load (); varNoreadgrid = ext.create (' Ext.grid.Panel '), {border:false, Store:noreadstore, columns: [{//Implementing IconsHeader: ' Name ', Dataindex:' Name ', Flex:1}], Emptytext:' No unread people. ‘                              }); Ext.create (' Ext.window ', {title:' Unread People list ', Width:180, Height:400, x:100, y:80, Plain:true, Headerposition:' Top ', layout:' Fit ', Items:noreadgrid}).                        Show (); }Else if(O.index = = 0){                            varReadstore = ext.create (' Ext.data.Store '), {fields: [' id ', ' name '], Proxy: {type:' Ajax ', API: {read:‘.. /mail/getreadmember.dhtml '}, Reader: { Type:' JSON ', Root:' Members '                                    }                                }                            });                            Readstore.load (); varReadgrid = ext.create (' Ext.grid.Panel '), {border:false, Store:readstore, columns: [{//Implementing IconsHeader: ' Name ', Dataindex:' Name ', Flex:1}], Emptytext:' There are no read people. ‘                              }); Ext.create (' Ext.window ', {title:' Read a list of people ', Width:180, Height:400, x:430, y:80, Plain:true, Headerposition:' Top ', layout:' Fit ', Items:readgrid}).                        Show (); }}, tips: {trackmouse:true, Width:140, Height:28, renderer:function(Storeitem, item) {//calculate percentage.                    varTotal = 0; Store1.each (function(REC) { total+ = Rec.get (' data1 ');                    });  This. Settitle (Storeitem.get (' name ') + ': ' + math.round (storeitem.get (' data1 ')/total * 100) + '% '); }}, highlight: {segment: {margin:20}}, Label: {field:' Name ', display:' Rotate ', Contrast:true, font:' 18px Arial '                }            }]        }); varPanel1 = ext.create (' Widget.panel '), {autowidth:true, Height:500, Title:' Read More ', RenderTo:Ext.getBody (), Layout:' Fit ', Tbar: [{text:' Save Chart ', Handler:function() {Ext.MessageBox.confirm (' OK download ', ' Do you want to save the chart as a picture? ' ‘,function(choice) {if(Choice = = ' Yes '{chart.save ({type:' Image/png '                        });            }                }); }}, {text:Refresh, Handler:function() {                //ADD A short delay to prevent fast sequential clicksWindow.loadTask.delay (100,function() {store1.reload ();            }); }}, {enabletoggle:true, pressed:false, Text:' Doughnut chart ', Togglehandler:function(BTN, pressed) {Chart.series.first (). Donut= pressed? 35:false;            Chart.refresh (); }], Items:chart});

Use basic as above, next click on the use of chart element events.

Start writing in the chart, can not find the expression of the click Area, and then add in the series, by returning the parameter o.index to get the click area of the label position, which for only two blocks of the chart is very useful, if more, it should be in the right index order. I didn't try, just a guess.

Event section:

series: [{                ' pie ',                ' data1 ',                true,                donut:donut,                Listeners: {                      function(o) {                         alert (o.index);}}            ]

Then I follow the index in the background processing data sent foreground generated window display.

ZP's ExtJS study notes (iv)--Simple use of charts (chart click events)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.