<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轴上的月份可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ChartJS Version 3 - common legend for multiple line charts(ChartJS 版本 3 - 多个折线图的常用图例)
                  Charts.js scales yaxes ticks min max doesnt work(Charts.js 缩放 yaxes 刻度 min max 不起作用)
                  How to expand the slice of donut chart in chartjs?(如何在chartjs中扩展圆环图的切片?)
                  Chart.js yAxes Ticks stepSize not working (fiddle)(Chart.js yAxes Ticks stepSize 不起作用(小提琴))
                  Rounded corners on chartJS v.2 - bar charts (with negative values)(chartJS v.2 上的圆角 - 条形图(带负值))
                  How to hide value in Chart JS bar(如何在 Chart JS 栏中隐藏值)
                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'>