我必须隐藏/删除所有数据点,除了倒数第二个点,如在此image中所示,我已经搜索了所有地方,但无法找到适当的解决方案来实现这一点。
myChart.datasets[0].points[0].display = false;
legStretchtCtx.update();
上面的代码片段是针对Chart.js Version 1.0的,但我使用的是Chart.js Version:2.7.1 .我已经使用了这个片段,但它给出了一个错误:
无法读取未定义的属性“0”
var legStretchtCtx = document.getElementById("leg-stretch-chart");
// var legStretch =
var myChart = new Chart(legStretchtCtx, {
type: 'line',
data: {
labels: ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6","Day 7"],
datasets: [{
label: 'Leg Stretch',
data: [3, 4, 5, 4, 3, 3.5, 3.5],
backgroundColor:"#70d6db",
borderColor: ["#70d6db"],
borderWidth: 4,
pointBackgroundColor: "#fff",
pointRadius: 8,
pointHoverRadius: 8,
pointHoverBackgroundColor: "#0ba8b0",
pointHoverBorderColor: "#26c1c9",
pointBorderColor:"#26c1c9"
}]
},
options: {
legend: {
display: false,
labels: {
display: true
}
},
responsive:true,
scales: {
xAxes: [{
gridLines: {
display: false,
drawBorder:false,
},
ticks: {
display: false,
fontFamily: "Montserrat",
fontColor: "#2c405a",
fontSize: 12
}
}],
yAxes: [{
gridLines: {
display: false,
drawBorder:false,
},
ticks: {
display: false,
fontFamily: "Montserrat",
fontColor: "#2c405a",
fontSize: 12,
stepSize:1,
min: 0,
max: 10,
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js"></script>
<div class="chart-container">
<div class="leg-stretch-chart-inner">
<canvas id="leg-stretch-chart" width="100%" height=""></canvas>
</div>
</div>
3条答案
按热度按时间62o28rlo1#
首先,将
pointRadius
改为array:然后,你必须用每个点的特定值重写这个数组(在我们的例子中,倒数第二个蓬特)并更新:
更多细节在此小提琴:https://jsfiddle.net/s7m1961t/
sg2wtvxw2#
dgenwo3n3#
适用于版本4.2.1如果按下复选框,则代码将事件显示为点,否则,图形没有点。
标签-日期。数据集-空缺数量