<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 向饼图添加工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  <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'>