<tfoot id='KKdvx'></tfoot>

    1. <i id='KKdvx'><tr id='KKdvx'><dt id='KKdvx'><q id='KKdvx'><span id='KKdvx'><b id='KKdvx'><form id='KKdvx'><ins id='KKdvx'></ins><ul id='KKdvx'></ul><sub id='KKdvx'></sub></form><legend id='KKdvx'></legend><bdo id='KKdvx'><pre id='KKdvx'><center id='KKdvx'></center></pre></bdo></b><th id='KKdvx'></th></span></q></dt></tr></i><div id='KKdvx'><tfoot id='KKdvx'></tfoot><dl id='KKdvx'><fieldset id='KKdvx'></fieldset></dl></div>
      <legend id='KKdvx'><style id='KKdvx'><dir id='KKdvx'><q id='KKdvx'></q></dir></style></legend>

        • <bdo id='KKdvx'></bdo><ul id='KKdvx'></ul>

      1. <small id='KKdvx'></small><noframes id='KKdvx'>

        使用 d3.js 向饼图添加工具提示

        adding tooltips to pie chart using d3.js(使用 d3.js 向饼图添加工具提示)
          <bdo id='Rss1i'></bdo><ul id='Rss1i'></ul>
        • <i id='Rss1i'><tr id='Rss1i'><dt id='Rss1i'><q id='Rss1i'><span id='Rss1i'><b id='Rss1i'><form id='Rss1i'><ins id='Rss1i'></ins><ul id='Rss1i'></ul><sub id='Rss1i'></sub></form><legend id='Rss1i'></legend><bdo id='Rss1i'><pre id='Rss1i'><center id='Rss1i'></center></pre></bdo></b><th id='Rss1i'></th></span></q></dt></tr></i><div id='Rss1i'><tfoot id='Rss1i'></tfoot><dl id='Rss1i'><fieldset id='Rss1i'></fieldset></dl></div>

        • <tfoot id='Rss1i'></tfoot>

                  <tbody id='Rss1i'></tbody>
                <legend id='Rss1i'><style id='Rss1i'><dir id='Rss1i'><q id='Rss1i'></q></dir></style></legend>
              1. <small id='Rss1i'></small><noframes id='Rss1i'>

                  本文介绍了使用 d3.js 向饼图添加工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开始学习使用 d3.js 可视化数据的旅程,到目前为止,我发现 Scott Murray 的交互式数据可视化"非常有用.我正在阅读本书第 11 章中的一些示例代码,并且想知道如何将工具提示添加到饼图中(本书已经使用条形图描述了此过程).无论如何,过去几个小时一直在修改代码,想看看是否有人可以帮我解决这个问题:

                  I am embarking on a journey to learn to visualize data using d3.js, and so far I am finding the "Interactive Data Visualization" by Scott Murray very helpful. I was following through some of the example codes in book chapter 11, and was wondering how I would add the tooltip to the pie chart (the book already describes this procedure using the bar chart). Anyways, just been tinkering around with the codes for past couple of hours and would like to see if anyone can lend me a hand on this:

                  <!DOCTYPE html>
                  <html lang="en">
                  <head>
                     <meta charset="utf-8">
                     <title>D3: Pie layout</title>
                     <script type="text/javascript" src="d3/d3.v3.js"></script>
                     <style type="text/css">
                  
                              text {
                                 font-family: sans-serif;
                                 font-size: 12px;
                                 fill: white;
                              }
                  
                              #tooltip {
                                 position: absolute;
                                 width: 200px;
                                 height: auto;
                                 padding: 10px;
                                 background-color: white;
                                 -webkit-border-radius: 10px;
                                 -moz-border-radius: 10px;
                                 border-radius: 10px;
                                 -webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
                                 -mox-box-shadow: 4px 4px 4px 10px rgba(0, 0, 0, 0.4);
                                 box-shadow: 4px 4px 10px rbga(0, 0, 0, 0.4)
                                 pointer-events: none;
                              }
                  
                              #tooltip.hidden {
                                 display: none;
                              }
                  
                             #tooltip p {
                                 margin: 0;
                                 font-family: sans-serif;
                                 font-size: 16px;
                                          line-height: 20px;
                             }
                     </style>
                  </head>
                  
                  <body>
                      <div id="tooltip" class="hidden">
                              <p><strong>Important Label Heading</strong></p>
                              <p><span id="value">100</span>%</p>
                      </div>
                      <script type="text/javascript">
                  
                          //Width and height
                          var w = 300;
                          var h = 300;
                  
                          var dataset = [ 5, 10, 20, 45, 6, 25 ];
                  
                          var outerRadius = w / 2;
                          var innerRadius = 0;
                          var arc = d3.svg.arc()
                                          .innerRadius(innerRadius)
                                          .outerRadius(outerRadius);
                  
                          var pie = d3.layout.pie();
                  
                          // Easy colors accessible via a 10-step ordinal scale
                          var color = d3.scale.category10();
                  
                          // Create SVG element
                          var svg = d3.select("body")
                                      .append("svg")
                                      .attr("width", w)
                                      .attr("height", h);
                  
                          // Set up groups
                          var arcs = svg.selectAll("g.arc")
                                        .data(pie(dataset))
                                        .enter()
                                        .append("g")
                                        .attr("class", "arc")
                                        .attr("transform", "translate(" + outerRadius + "," + outerRadius + ")")
                                        .on("mouseover", function(d){
                                          d3.select("#tooltip")
                                            .select("#value")
                                            .text(d);
                  
                                          d3.select("tooltip").classed("hidden",false);
                                        })
                                        .on("mouseout", function() {
                                          // Hide the tooltip
                                          d3.select("#tooltip").classed("hidden", true);
                                        });
                  
                          // Draw arc paths
                          arcs.append("path")
                              .attr("fill", function(d, i) {
                                   return color(i);
                              })
                              .attr("d", arc);
                  
                          // Labels
                          arcs.append("text")
                              .attr("transform", function(d) {
                                   return "translate(" + arc.centroid(d) + ")";
                              })
                              .attr("text-anchor", "middle")
                              .text(function(d) {
                                   return d.value;
                              });
                      </script>
                  </body>
                  </html>
                  

                  我知道这有点难以理解,但我想更具体地了解如何设置工具提示的 x 和 y 值.提前谢谢你.

                  I know this is bit to digest, but what I want to know more specifically is how to set the x and y value for the tool-tip. Thank you in advance.

                  推荐答案

                  我更喜欢使用不透明度来显示/隐藏工具提示.这是 FIDDLE.这应该能让你继续前进.

                  I prefer to use the opacity to show/hide the tooltip. Here is the FIDDLE. This should get you going.

                  d3.select("#tooltip")
                      .style("left", d3.event.pageX + "px")
                      .style("top", d3.event.pageY + "px")
                      .style("opacity", 1)
                      .select("#value")
                      .text(d.value);
                  

                  这篇关于使用 d3.js 向饼图添加工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                  How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                  Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                  How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                  Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
                  div hover background-color change?(div 悬停背景颜色变化?)
                  <legend id='ZzZfg'><style id='ZzZfg'><dir id='ZzZfg'><q id='ZzZfg'></q></dir></style></legend>
                • <tfoot id='ZzZfg'></tfoot>

                        <bdo id='ZzZfg'></bdo><ul id='ZzZfg'></ul>
                            <tbody id='ZzZfg'></tbody>
                          <i id='ZzZfg'><tr id='ZzZfg'><dt id='ZzZfg'><q id='ZzZfg'><span id='ZzZfg'><b id='ZzZfg'><form id='ZzZfg'><ins id='ZzZfg'></ins><ul id='ZzZfg'></ul><sub id='ZzZfg'></sub></form><legend id='ZzZfg'></legend><bdo id='ZzZfg'><pre id='ZzZfg'><center id='ZzZfg'></center></pre></bdo></b><th id='ZzZfg'></th></span></q></dt></tr></i><div id='ZzZfg'><tfoot id='ZzZfg'></tfoot><dl id='ZzZfg'><fieldset id='ZzZfg'></fieldset></dl></div>

                          <small id='ZzZfg'></small><noframes id='ZzZfg'>