Javascript chart.js在空白数据上不可见
我想在没有数据的情况下显示图表。在这种情况下,x轴和y轴显示为可见。这是我使用的代码。即使没有数据,如何使图形可见Javascript chart.js在空白数据上不可见,javascript,chart.js,Javascript,Chart.js,我想在没有数据的情况下显示图表。在这种情况下,x轴和y轴显示为可见。这是我使用的代码。即使没有数据,如何使图形可见 <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.min.js"></script> <style type="text/css"> </style> <
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.min.js"></script>
<style type="text/css">
</style>
</head>
<body>
<canvas id="myChart"></canvas>
<script>
const ctx = document.getElementById('myChart');
var barChart = new Chart(ctx,{
type: 'line',
data:{
datasets: [
{
fill: false,
lineTension: 0.1,
backgroundColor: "#22a7f0",
borderColor: "#22a7f0",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 5,
pointHitRadius: 40,
data: []
}
]
},
options: {
legend: {
display: false
},
tooltips: {
enabled: true,
//mode: 'single',
mode: 'label'
},
maintainAspectRatio: false,
scales: {
xAxes: [{
gridLines: {
display:false
}
}],
yAxes: [{
gridLines: {
display:false
}
}]
}
}
});
</script>
</body>
const ctx=document.getElementById('myChart');
var条形图=新图表(ctx{
键入:“行”,
数据:{
数据集:[
{
填充:假,
线张力:0.1,
背景色:“22a7f0”,
边框颜色:“22a7f0”,
borderCapStyle:“butt”,
borderDash:[],
borderDashOffset:0.0,
borderJoinStyle:'斜接',
pointBorderColor:“rgba(75192192,1)”,
pointBackgroundColor:#fff“,
点边界宽度:1,
点半径:5,
pointHoverBackgroundColor:“rgba(75192192,1)”,
pointHoverBorderColor:“rgba(2201)”,
pointHoverBorderWidth:2,
点半径:5,
点半径:40,
数据:[]
}
]
},
选项:{
图例:{
显示:假
},
工具提示:{
启用:对,
//模式:“单一”,
模式:“标签”
},
MaintaintAspectRatio:false,
比例:{
xAxes:[{
网格线:{
显示:假
}
}],
雅克斯:[{
网格线:{
显示:假
}
}]
}
}
});
如果只想显示图形,则无需设置
网格线
选项。它默认显示
此外,数据
对象中没有标签
,因此网格线显示不正确
以下是固定版本:
const ctx=document.getElementById('myChart');
var条形图=新图表(ctx{
键入:“行”,
数据:{
标签:[1,2,3,4,5,6],
数据集:[{
填充:假,
线张力:0.1,
背景色:“22a7f0”,
边框颜色:“22a7f0”,
borderCapStyle:“butt”,
borderDash:[],
borderDashOffset:0.0,
borderJoinStyle:'斜接',
pointBorderColor:“rgba(75192192,1)”,
pointBackgroundColor:#fff“,
点边界宽度:1,
点半径:5,
pointHoverBackgroundColor:“rgba(75192192,1)”,
pointHoverBorderColor:“rgba(2201)”,
pointHoverBorderWidth:2,
点半径:5,
点半径:40,
数据:[]
}]
},
选项:{
图例:{
显示:假
},
工具提示:{
启用:对,
模式:“标签”
},
MaintaintAspectRatio:false,
比例:{
雅克斯:[{
滴答声:{
分:0,,
最多:500
}
}]
}
}
});代码>
请阅读-总结是,这不是向志愿者讲话的理想方式,可能会对获得答案产生反作用。请不要在你的问题中添加这一点。离题:一个人的豪爽(铜板、自信、傲慢)不是一个人拥有的东西,而不是一个人的本来面目吗?也许我错过了一个笑话…@halfer-lol。。我甚至忘了我有阿凡达xD。。。顺便说一句,不知道那个笑话透:)啊,对了。好吧,这没关系,但恐怕这个消息没有多大意义。:-)
。很有趣,谢谢。它起作用了。你能告诉我如何在Y轴上定制单位吗。谢谢男人们:)