简体   繁体   English

D3 js在单击圆弧时出现角度2弹出窗口

[英]D3 js with angular 2 popup on clicking the arc of pie

 public drawPie() {
 let g = this.svg.selectAll(".arc")
                .data(this.pie(this.Stats))
                      .enter().append("g")
                .attr("class", "arc");
g.append("path").attr("d", this.arc)
                 .on("click",function(event){ console.log(JSON.stringify(event))
                     alert("hello");
                  var person = {
                  fullName: function() {
                    alert("hai");
                   // I want popup code here on click event.                                               
                  }
              }

              person.fullName();
                  ;})

                .style("fill", (d: any) => this.color(d.data.key) );
g.append("text").attr("transform", (d: any) => "translate(" + this.labelArc.centroid(d) + ")")
                .attr("dy", ".35em")
                .text((d: any) => d.data.key+": "+d.value);
 }   

On clicking the arc of pie chart one popup should come and I want to display some data regarding that arc.I am not getting popup. 单击饼形图的弧时,应该弹出一个窗口,我想显示有关该弧的一些数据。我没有弹出窗口。 can anyone give me suggestion... 谁能给我建议...

I feel like you need to make a connection between view layer of Angular and the place of code which corresponding to showing the popup. 我觉得您需要在Angular的视图层和对应于显示弹出窗口的代码位置之间建立连接。

So, place a popup inside of your HTML, and hide it by default with the some *ngIf="showPopup" statement. 因此,在您的HTML中放置一个弹出窗口,并默认使用*ngIf="showPopup"语句将其隐藏。 After, you will need to make two things inside the block which should trigger the call of the popup: 之后,您将需要在块内做两件事,这将触发弹出窗口的调用:

  1. Using ViewChild decorator get the element from your view, and set right X, Y positions for this element, so it will be placed exactly close to the place it was clicked. 使用ViewChild装饰器从您的视图中获取该元素,并为此元素设置正确的X,Y位置,以便将其放置在与单击位置完全接近的位置。
  2. Set showPopup property to the true value, so it will appear. showPopup属性设置为true值,它将出现。

Let me know about your progress on this one. 让我知道您在这一方面的进展。 Good luck! 祝好运!

  .on("click",function(event){ console.log(JSON.stringify(event))

                 this.parameter_name=event.data.key;
                 console.log("the clicked paramter name is"+ this.parameter_name);
                 var person = {
                  fullName: function() {
                    var newDiv = document.createElement("div");  

                    newDiv.innerHTML +='<div id="popup" style=" position: absolute;width: 900px ;z-index: 999;display: none;top:150px;margin-left: 350px;margin-right:500px;background-color: #fff;  border: 1px solid #ddd;  border-radius: 5px;  box-shadow: 0 2px 8px #aaa;  overflow: hidden;   padding: 10px;">'+
                    '<div class="popup_body table-responsive" style="  height: 500px; margin-bottom:10px; ">Recon Report'+                                  
                    '<table class="table table-striped table-bordered table-hover"><thead class="thead-inverse"><tr>'+
                         '<th>#</th>'+
                         '<th>First Name</th>'+
                         '<th>Last Name</th>'+
                         '<th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th><th>Username</th></tr></thead>'+
                         '<tbody><tr *ngFor="let employee of allEmployees">'+
                         '<td>abc</td>'+
                         '<td>abc</td>'+
                         '<td>abc</td></tr>'+



                    '</tbody></table></div>'+
                    '<button type="button" class="btn btn-primary pull-right" style="margin:5px"  onClick="(function(){ var el = document.getElementById(\'popup\'); el.style.display = \'none\'; document.body.style.background = \'white\';})();">close</button>'+
                    '<button type="button" class="btn btn-primary pull-right" style="margin:5px" onClick="(download_csv())">Download CSV</button></div>
                    var currentDiv = document.getElementById("main_container"); 
                    document.body.insertBefore(newDiv, currentDiv); 

                    // open popup onClick
                    openPopup();

                  }

              }

I have created popup as shown in the code. 我已经创建了弹出窗口,如代码所示。 The popup is coming but on click event I need to call this._myserviceService.reconSrcData(this.recon_name,this.recon_startdate).subscribe(data1 =>{ console.log("the return pie srccccc data is"+ JSON.stringify(data1)); }); 弹出窗口即将到来,但在单击事件上,我需要调用此函数。_myserviceService.reconSrcData(this.recon_name,this.recon_startdate).subscribe(data1 => {console.log(“返回饼图srccccc数据为” + JSON.stringify( data1));});

inorder to display the data by collecting through ajax call from spring mvc. 为了通过从Spring MVC通过Ajax调用收集来显示数据。 But when I placed the code in click event it was showing error like "Cannot read property 'reconSrcData' of undefined" 但是,当我将代码放在click事件中时,它显示了类似“无法读取未定义的属性'reconSrcData'的错误”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM