chartjs tooltip is cut off when out of canvas(离开画布时,chartjs 工具提示被切断)
本文介绍了离开画布时,chartjs 工具提示被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用 chartjs (
解决方案
有多种解决方法.
一种方法(在你的情况下),你可以解决这个问题,就是为你的图表布局设置底部填充,就像这样......
选项:{布局: {填充:{底部:25//最适合的设置}},...}
ᴅᴇᴍᴏ
var ctx = document.getElementById("myChart").getContext('2d');var myChart = new Chart(ctx, {类型:'线',数据: {标签:['一月','二月','三月','四月','五月','六月','七月','八月','九月'],数据集:[{标签:'标准评级',数据:[0.1, 0.02, 3, 4, 5, 6, 7, 8, 9],backgroundColor: 'rgba(209, 230, 245, 0.5)',borderColor: 'rgba(56, 163, 236, 1)',边框宽度:1}]},选项: {布局: {填充:{底部:25//最适合的设置}},响应:错误,工具提示:{yAlign: '顶部'}}});
<script src="aHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvQ2hhcnQuanMvMi41LjAvQ2hhcnQubWluLmpz"></脚本><canvas id="myChart" width="350" height="200"></canvas>
I'm currently using chartjs (chartjs).
Tooltip is cutted, because it go out of canvas. How I can fix this behavior?
解决方案
There are multiple ways of solving this.
One way (in your case), you can solve this, is by setting the bottom padding for your chart layout , like so ...
options: {
layout: {
padding: {
bottom: 25 //set that fits the best
}
},
...
}
ᴅᴇᴍᴏ
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept'],
datasets: [{
label: 'Standard Rating',
data: [0.1, 0.02, 3, 4, 5, 6, 7, 8, 9],
backgroundColor: 'rgba(209, 230, 245, 0.5)',
borderColor: 'rgba(56, 163, 236, 1)',
borderWidth: 1
}]
},
options: {
layout: {
padding: {
bottom: 25 //set that fits the best
}
},
responsive: false,
tooltips: {
yAlign: 'top'
}
}
});
<script src="aHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9hamF4L2xpYnMvQ2hhcnQuanMvMi41LjAvQ2hhcnQubWluLmpz"></script>
<canvas id="myChart" width="350" height="200"></canvas>
这篇关于离开画布时,chartjs 工具提示被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:离开画布时,chartjs 工具提示被切断


猜你喜欢
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01