このimageのように、2番目の最後の点を除くすべてのデータポイントを非表示/削除する必要がありますが、これを達成するための適切な解決策はありませんでした。スニペットの上
chartjsのいくつかの点を削除する方法
myChart.datasets[0].points[0].display = false;
legStretchtCtx.update();
はChart.jsバージョン1.0用ですが、私はChart.jsバージョンを使用しています:2.7.1。私はこのスニペットを使用しているが、そのエラーを与える:
Cannot read property '0' of undefined
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],
\t \t \t \t backgroundColor:"#70d6db",
borderColor: ["#70d6db"],
borderWidth: 4,
pointBackgroundColor: "#fff",
pointRadius: 8,
pointHoverRadius: 8,
\t \t \t \t pointHoverBackgroundColor: "#0ba8b0",
pointHoverBorderColor: "#26c1c9",
\t \t \t \t pointBorderColor:"#26c1c9"
}]
},
options: {
legend: {
display: false,
labels: {
display: true
}
},
\t \t \t responsive:true,
scales: {
xAxes: [{
gridLines: {
display: false,
drawBorder:false,
},
ticks: {
display: false,
fontFamily: "Montserrat",
fontColor: "#2c405a",
\t \t \t \t \t \t fontSize: 12
}
}],
yAxes: [{
gridLines: {
display: false,
drawBorder:false,
},
ticks: {
\t \t \t \t \t \t display: false,
\t \t \t \t \t \t fontFamily: "Montserrat",
fontColor: "#2c405a",
\t fontSize: 12,
\t \t \t \t \t \t stepSize:1,
min: 0,
max: 10,
\t \t \t \t \t }
}]
}
}
});
<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>
これは、ボタンのクリックで完全に働いたが、私はそれを修正していると、文書内のすべてのチャートのためにdocument.ready機能でそれをトリガー –