I am trying to create a line chart
that presents score level from 1-100.
Line is static and needs to be curved
but the dot on the chart is dynamic value and by that it changes its location along the existing line.
First I was thinking to add additional data that represents only the dot itself, but Y(height)
is unknown.
Second attempt led me to create a second line that crosses / intersects the first one in hope of finding intersection point and making it a dot.
Unfortunately, I couldn't find a way to locate intersection.
new Chart(
document.getElementById('lineChart'), {
type: 'line',
data: {
datasets: [
{
data: [
{
x: 70, y: 0,
},
{
x: 70, y: 100,
}],
fill: false,
borderColor: 'red',
showLine:true,
},
{
data: [
{
x: 0, y: 2,
},
{
x: 25, y: 10,
},
{
x: 50, y: 50,
},
{
x: 80, y: 90,
},
{
x: 100, y: 98,
}],
startWithZero: true,
fill: false,
lineTension: 0.3,
borderColor: 'blue',
}
]
},
options: {
bezierCurve : true,
lineTension: 0.3,
tooltips: {
mode: 'intersect'
},
scales: {
xAxes: [{
type: 'linear',
ticks: {
min: 0, //minimum tick
max: 100, //maximum tick
},
}],
yAxes: [{
ticks: {
bezierCurve : true,
min: 0, //minimum tick
max: 100, //maximum tick
},
bezierCurve : true,
type: 'linear',
lineTension: 0.3,
scaleLabel: {
lineTension: 0.1,
display: true,
}
}]
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
<body>
<div style="width: 750px; height: 250px; margin: 0 auto;">
<canvas style="width: 750px; height: 250px" id="lineChart"></canvas>
</div>
</body>