ChartJS 如何改进移动端的点击区域。

huangapple go评论47阅读模式
英文:

ChartJS how to improve mobile tap areas

问题

一些用户提到很难点击图表点以查看其工具提示数据。是否有增加可点击点区域的方法?

英文:

Some of my users have mentioned that its hard to tap a chart point to see its tooltip data. Is there a way to increase the area of clickable points?

ChartJS 如何改进移动端的点击区域。

答案1

得分: 2

你可以将pointHitRadius设置为一个较大的数字:

const options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        pointHitRadius: 25
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        pointHitRadius: 25
      }
    ]
  },
  options: {}
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.2.0/chart.umd.js"></script>

<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>
英文:

You can set the pointHitRadius to a higher number:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const options = {
  type: &#39;line&#39;,
  data: {
    labels: [&quot;Red&quot;, &quot;Blue&quot;, &quot;Yellow&quot;, &quot;Green&quot;, &quot;Purple&quot;, &quot;Orange&quot;],
    datasets: [{
        label: &#39;# of Votes&#39;,
        data: [12, 19, 3, 5, 2, 3],
        pointHitRadius: 25
      },
      {
        label: &#39;# of Points&#39;,
        data: [7, 11, 5, 8, 3, 7],
        pointHitRadius: 25
      }
    ]
  },
  options: {}
}

const ctx = document.getElementById(&#39;chartJSContainer&#39;).getContext(&#39;2d&#39;);
new Chart(ctx, options);

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.2.0/chart.umd.js&quot;&gt;&lt;/script&gt;

&lt;body&gt;
  &lt;canvas id=&quot;chartJSContainer&quot; width=&quot;600&quot; height=&quot;400&quot;&gt;&lt;/canvas&gt;
&lt;/body&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月6日 02:11:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定