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

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

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

        Chart.js 将标签变成链接

        Chart.js turn labels into links(Chart.js 将标签变成链接)
        • <i id='FJu3g'><tr id='FJu3g'><dt id='FJu3g'><q id='FJu3g'><span id='FJu3g'><b id='FJu3g'><form id='FJu3g'><ins id='FJu3g'></ins><ul id='FJu3g'></ul><sub id='FJu3g'></sub></form><legend id='FJu3g'></legend><bdo id='FJu3g'><pre id='FJu3g'><center id='FJu3g'></center></pre></bdo></b><th id='FJu3g'></th></span></q></dt></tr></i><div id='FJu3g'><tfoot id='FJu3g'></tfoot><dl id='FJu3g'><fieldset id='FJu3g'></fieldset></dl></div>
            <legend id='FJu3g'><style id='FJu3g'><dir id='FJu3g'><q id='FJu3g'></q></dir></style></legend>
          • <small id='FJu3g'></small><noframes id='FJu3g'>

              • <bdo id='FJu3g'></bdo><ul id='FJu3g'></ul>
                <tfoot id='FJu3g'></tfoot>

                    <tbody id='FJu3g'></tbody>
                  本文介绍了Chart.js 将标签变成链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果不执行以下操作,我不确定这是否可行:在HTML 画布,但让我们确定一下.

                  I'm not sure this is possible without doing something along the line of: Create links in HTML canvas but let's make sure.

                  有没有办法(相对)简单地将 Chart.js 标签转换为链接?有问题的图表是雷达图:http://www.chartjs.org/docs/#雷达图(到目前为止,我一直在使用图例,只需稍加修改库即可正常工作,但现在我应该使用标签本身.)

                  Is there a way to (relatively) simply turn Chart.js labels into links? The chart in question is the radar chart: http://www.chartjs.org/docs/#radar-chart (So far I've been using the legend for that, works fine with a little library modification, but now I should use the labels themselves.)

                  推荐答案

                  你可以监听点击事件,然后遍历所有的pointLabels,检查点击是否在那个框内.如果是这种情况,您可以从包含所有标签的数组中获取相应的标签.

                  You can listen to the click event and then loop through all the pointLabels check if the click is in that box. If this is the case you get the corresponding label from the array containing all the labels.

                  然后你可以打开使用 window.location = linkwindow.open(link) 去你的链接.

                  Then you can open use window.location = link or window.open(link) to go to your link.

                  点击后在 google 上搜索颜色的示例:

                  Example that searches the color on google on click:

                  const options = {
                    type: 'radar',
                    data: {
                      labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
                      datasets: [{
                          label: '# of Votes',
                          data: [12, 19, 3, 5, 2, 3],
                          borderColor: 'orange'
                        },
                        {
                          label: '# of Points',
                          data: [7, 11, 5, 8, 3, 7],
                          borderColor: 'pink'
                        }
                      ]
                    },
                    options: {
                      onClick: (evt, activeEls, chart) => {
                        const {
                          x,
                          y
                        } = evt;
                        let index = -1;
                  
                        for (let i = 0; i < chart.scales.r._pointLabelItems.length; i++) {
                          const {
                            bottom,
                            top,
                            left,
                            right
                          } = chart.scales.r._pointLabelItems[i];
                  
                          if (x >= left && x <= right && y >= top && y <= bottom) {
                            index = i;
                            break;
                          }
                        }
                  
                        if (index === -1) {
                          return;
                        }
                  
                        const clickedLabel = chart.scales.r._pointLabels[index];
                  
                        window.open(`https://www.google.com/search?q=color%20${clickedLabel}`); // Blocked in stack snipet. See fiddle
                        console.log(clickedLabel)
                      }
                    }
                  }
                  
                  const ctx = document.getElementById('chartJSContainer').getContext('2d');
                  new Chart(ctx, options);

                  <body>
                    <canvas id="chartJSContainer" width="600" height="400"></canvas>
                    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.0/chart.js"></script>
                  </body>

                  小提琴:https://jsfiddle.net/Leelenaleee/fnqr4c7j/22/

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

                      <bdo id='80unx'></bdo><ul id='80unx'></ul>
                          <tbody id='80unx'></tbody>
                        <tfoot id='80unx'></tfoot>
                      1. <small id='80unx'></small><noframes id='80unx'>

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