超出画布时,chartjs工具提示将被切断 [英] chartjs tooltip is cut off when out of canvas

查看:81
本文介绍了超出画布时,chartjs工具提示将被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用chartjs(

解决方案

有多种解决方法。



(针对您的情况)的一种解决方法是通过设置图表布局的底部填充,像这样...

 选项:{
布局:{
padding:{
bottom:25 //最适合的
} set
},
...
}

ᴅᴇᴍᴏ



  var ctx = document.getElementById( myChart)。getContext('2d'); var myChart = new Chart(ctx,{type:'line ',数据:{标签:['Jan','Feb','Mar', 'Apr','May','Jun','Jul','Aug','Sept'],数据集:[{标签:标准评分,数据:[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}]},选项:{ {padding:{bottom:25 //最合适的集合}},响应:false,工具提示:{yAlign:'top'}}});  

 < script src = https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/ Chart.min.js>< / script><画布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="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="myChart" width="350" height="200"></canvas>

这篇关于超出画布时,chartjs工具提示将被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆