gpt4 book ai didi

chart.js - ChartJS : How to leave just points without lines

转载 作者:行者123 更新时间:2023-12-04 09:58:01 24 4
gpt4 key购买 nike

我有以下ChartJS图表:

enter image description here

I would like to know how can I remove the connecting lines between dots, because I just need to show the dots.



这是实际的代码:
 var data = {
labels: ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"],
datasets: [{
data: [0.2, 0.1, 0.4, 0.1, 0.0, 0.5, 0.4]
}, {
data: [0.3, 0.2, 0.4, 0.4, 0.0, 0.7, 0.6]
},
{
data: [0.4, 0.5, 0.5, 0.4, 0.0, 0.9, 0.7]
},
{
data: [0.6, 0.7, 0.55, 0.6, 0.0, 0.9, 0.7]
}]
};

var ctx = document.getElementById("LineWithLine").getContext("2d");

Chart.types.Line.extend({
name: "LineWithLine",
initialize: function () {
Chart.types.Line.prototype.initialize.apply(this, arguments);
},
draw: function () {
Chart.types.Line.prototype.draw.apply(this, arguments);

var point = this.datasets[0].points[this.options.lineAtIndex]
var scale = this.scale
//console.log(this);

// draw line
this.chart.ctx.beginPath();
this.chart.ctx.moveTo(scale.startPoint + 12, scale.calculateY(0.6));
this.chart.ctx.strokeStyle = '#ff0000';
this.chart.ctx.lineTo(this.chart.width, scale.calculateY(0.6));
this.chart.ctx.stroke();

// write TODAY
this.chart.ctx.textAlign = 'center';
//this.chart.ctx.fillText("TODAY", scale.startPoint + 35, point.y + 10);

this.chart.ctx.restore();
}
});

new Chart(ctx).LineWithLine(data, {
datasetFill: false,
lineAtIndex: 0.6
});

最佳答案

要仅显示点,您需要为数据集将 showLine 属性设置为 false

这是一个例子:

var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
datasets: [{
label: '# of votes',
data: [3, 4, 1, 5, 6],
pointBackgroundColor: 'black',
pointRadius: 5,
fill: false,
showLine: false //<- set this
}]
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

关于chart.js - ChartJS : How to leave just points without lines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45114098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com