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

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

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

      1. <tfoot id='eZpxy'></tfoot>
          <bdo id='eZpxy'></bdo><ul id='eZpxy'></ul>
      2. 在chart.js折线图上使x轴上的月份可点击

        Make months on x-axis clickable on chart.js line chart(在chart.js折线图上使x轴上的月份可点击)
          <tbody id='if3I6'></tbody>
      3. <tfoot id='if3I6'></tfoot>
        <legend id='if3I6'><style id='if3I6'><dir id='if3I6'><q id='if3I6'></q></dir></style></legend>

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

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

              <bdo id='if3I6'></bdo><ul id='if3I6'></ul>
                1. 本文介绍了在chart.js折线图上使x轴上的月份可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 chart.js 创建折线图.我的 x 轴基于时间并显示月份.
                  每个月列"都应该是可点击/可选择的,但我找不到管理它的方法.getElementAtEvent() 之类的方法返回数据,因此我可以找出选择了哪个月份.但它们仅在用户单击某个点时才有效,而不是列"中的任何位置.

                  I'm creating a line chart with chart.js. My x-axis is time-based and displays months.
                  Each "month column" should be clickable/selectable, but I cannot find a way to manage this. Methods like getElementAtEvent() return data, so I can find out which month is selected. But they only work if the user clicks right on a point, and not anywhere in the "column".

                  我该怎么做?还是已经有这个插件?

                  How can I do that? Or is there already a plugin for this?

                  推荐答案

                  我能够使用一个名为 .getValueForPixel() 的未记录的时间尺度原型方法来完成这个工作,它返回的尺度值被点击的比例区域.

                  I was able to get this working using an undocumented time scale prototype method called .getValueForPixel(), which returns the scale value of the scale region that was clicked.

                  此方法返回一个用于生成刻度刻度标签的时刻对象,因此您可以在显示此值时使用为您的时间刻度配置的相同格式字符串(如果您希望它们在视觉上相等).我将它与通用 onClick 选项配置相结合property 为您想要做的事情提供了一种非常简单的方法.

                  This method returns a moment object that was used to generate the scale tick label, so you can use the same format string configured for your time scale when displaying this value (if you want them to be visually equal). I coupled this with the generic onClick option config property for a pretty simple approach for what you are wanting to do.

                  这里是如何做到这一点.在您的 options 对象中,使用此函数添加 onClick 属性.

                  Here is how to do it. In your options object, add an onClick property using this function.

                  onClick: function(e) {
                    var xLabel = this.scales['x-axis-0'].getValueForPixel(e.x);
                    console.log(xLabel.format('MMM YYYY'));
                    alert("clicked x-axis area: " + xLabel.format('MMM YYYY'));
                  },
                  

                  这里有一个 codepen 示例来查看它的实际效果.

                  Here is a codepen example to see it in action.

                  这篇关于在chart.js折线图上使x轴上的月份可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                  问题描述: 在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中的序数)
                2. <legend id='x4nbB'><style id='x4nbB'><dir id='x4nbB'><q id='x4nbB'></q></dir></style></legend>

                  <tfoot id='x4nbB'></tfoot>
                      <bdo id='x4nbB'></bdo><ul id='x4nbB'></ul>

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

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