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

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

          <bdo id='bfPGP'></bdo><ul id='bfPGP'></ul>

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

        在 Chart.js 段中嵌入唯一标识符?

        Embed unique identifier in Chart.js segments?(在 Chart.js 段中嵌入唯一标识符?)
        <i id='FUecZ'><tr id='FUecZ'><dt id='FUecZ'><q id='FUecZ'><span id='FUecZ'><b id='FUecZ'><form id='FUecZ'><ins id='FUecZ'></ins><ul id='FUecZ'></ul><sub id='FUecZ'></sub></form><legend id='FUecZ'></legend><bdo id='FUecZ'><pre id='FUecZ'><center id='FUecZ'></center></pre></bdo></b><th id='FUecZ'></th></span></q></dt></tr></i><div id='FUecZ'><tfoot id='FUecZ'></tfoot><dl id='FUecZ'><fieldset id='FUecZ'></fieldset></dl></div>
            • <small id='FUecZ'></small><noframes id='FUecZ'>

              <legend id='FUecZ'><style id='FUecZ'><dir id='FUecZ'><q id='FUecZ'></q></dir></style></legend>

                <tfoot id='FUecZ'></tfoot>
                • <bdo id='FUecZ'></bdo><ul id='FUecZ'></ul>
                    <tbody id='FUecZ'></tbody>
                • 本文介绍了在 Chart.js 段中嵌入唯一标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想让我的饼图具有交互性,允许用户双击一个切片向下钻取.我相信这样做的方法是在画布上创建一个 onclick 处理程序,并使用 getSegmentsAtEvent() 来确定单击了哪个切片.

                  I want to make my pie-chart interactive by allowing the user to double-click on a slice to drill down. I believe that the way to do this is to create an onclick handler on the canvas, and use getSegmentsAtEvent() to determine which slice was clicked.

                  调用 getSegmentsAtEvent() 返回的段数据可能不明确.以下是返回数据的示例:

                  The segment data returned by the call to getSegmentsAtEvent() is possibly ambiguous though. Here is a sample of the returned data:

                  [{
                      "circumference": 4.1887902047863905,
                      "endAngle": 8.901179185171081,
                      "fillColor": "#FF5A5E",
                      "highlightColor": "#FF5A5E",
                      "innerRadius": 0,
                      "label": "Red",
                      "outerRadius": 99.5,
                      "showStroke": true,
                      "startAngle": 4.71238898038469,
                      "strokeColor": "#fff",
                      "strokeWidth": 2,
                      "value": 300
                  }]
                  

                  在这些字段中,只有 valuefillColorhighlightColorlabel 由我提供,并且它们都不一定是唯一的.我可以确保 label 是唯一的,但这可能会降低人类的可读性.

                  Of those fields, only value, fillColor, highlightColor, and label are supplied by me, and none of them are necessarily unique. I could ensure that label is unique, but that might make it less readable for humans.

                  我尝试在传递给 Pie() 的数据中添加一个附加属性(例如id"),但是当我从该调用中取回段数据时,它被删除了.有没有办法在不重载 label 字段的情况下为每个段添加一个属性,我可以用它来肯定地识别它们?

                  I have tried adding an additional property (e.g. "id") into the data I pass into Pie(), but it is stripped out when I get the segment data back from this call. Is there a way to add a property to each segment which I can use to positively identify them, without overloading the label field?

                  推荐答案

                  您需要覆盖饼图或创建从饼图继承的新图表类型.

                  You would need to either override the pie chart or create a new chart type that inherits from pie.

                  这是一个新图表类型的示例,我传递了一个名为 id 的新属性,然后在此图表中唯一需要不同的是,当添加数据时,此 id 需要传递给图表

                  Here is an example of a new chart type, i have passed a new attribute called id and then the only thing that needs to be different in this chart is that when the data is being added this id needs to passed to the chart

                  Chart.types.Pie.extend({
                      name: "PieUnique",
                      addData: function (segment, atIndex, silent) {
                          var index = atIndex || this.segments.length;
                          this.segments.splice(index, 0, new this.SegmentArc({
                              value: segment.value,
                              outerRadius: (this.options.animateScale) ? 0 : this.outerRadius,
                              innerRadius: (this.options.animateScale) ? 0 : (this.outerRadius / 100) * this.options.percentageInnerCutout,
                              fillColor: segment.color,
                              highlightColor: segment.highlight || segment.color,
                              showStroke: this.options.segmentShowStroke,
                              strokeWidth: this.options.segmentStrokeWidth,
                              strokeColor: this.options.segmentStrokeColor,
                              startAngle: Math.PI * this.options.startAngle,
                              circumference: (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
                              label: segment.label,
                              //add option passed
                              id: segment.id
                          }));
                          if (!silent) {
                              this.reflow();
                              this.update();
                          }
                      },
                  });
                  
                  var pieData = [{
                      value: 300,
                      color: "#F7464A",
                      highlight: "#FF5A5E",
                      label: "Red",
                      id: "1-upi"
                  }, {
                      value: 50,
                      color: "#46BFBD",
                      highlight: "#5AD3D1",
                      label: "Green",
                      id: "2-upi"
                  }, {
                      value: 100,
                      color: "#FDB45C",
                      highlight: "#FFC870",
                      label: "Yellow",
                      id: "3-upi"
                  }, {
                      value: 40,
                      color: "#949FB1",
                      highlight: "#A8B3C5",
                      label: "Grey",
                      id: "4-upi"
                  }, {
                      value: 120,
                      color: "#4D5360",
                      highlight: "#616774",
                      label: "Dark Grey",
                      id: "5-upi"
                  }
                  
                  ];
                  
                  
                  var ctx = document.getElementById("chart-area").getContext("2d");
                  window.myPie = new Chart(ctx).PieUnique(pieData);
                  
                  document.getElementById("chart-area").onclick = function (evt) {
                      var activePoints = window.myPie.getSegmentsAtEvent(evt);
                      //you can now access the id at activePoints[0].id
                      console.log(activePoints);
                  
                  
                  };

                  <script src="https://raw.githack.com/leighquince/Chart.js/master/Chart.js"></script>
                  <canvas id="chart-area" width="400"></canvas>

                  这篇关于在 Chart.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 在一年的第一天返回前一年)

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

                    <tfoot id='rI04y'></tfoot>
                        <tbody id='rI04y'></tbody>

                    1. <legend id='rI04y'><style id='rI04y'><dir id='rI04y'><q id='rI04y'></q></dir></style></legend>
                        <bdo id='rI04y'></bdo><ul id='rI04y'></ul>

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