-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (77 loc) · 2.03 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plot Points</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"></script>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<div>
<label for="pointsInput">Enter points:</label>
<textarea id="pointsInput" rows="10"></textarea>
<button onclick="plotPoints()">Plot Points</button>
</div>
<canvas id="myChart" width="800" height="400"></canvas>
<script>
function plotPoints() {
// Getting the input value and parsing JSON
const input = document.getElementById('pointsInput').value;
const data = JSON.parse(input);
// Extracting x and y values
const colorTransfer = data.colorTransfer;
const scalarOpacity = data.scalarOpacity;
const xValues = [];
const yValues = [];
// Extracting x values from colorTransfer
const colorTransferValues = colorTransfer.split(' ');
for (let i = 1; i < colorTransferValues.length; i += 4) {
const x = parseFloat(colorTransferValues[i]);
xValues.push(x);
}
// Extracting y values from scalarOpacity
const scalarOpacityValues = scalarOpacity.split(' ');
for (let i = 1; i < scalarOpacityValues.length; i += 2) {
const y = parseFloat(scalarOpacityValues[i+1]);
yValues.push(y);
}
// Plotting the points using Chart.js
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: xValues,
datasets: [{
label: 'Points',
data: yValues,
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1,
fill: false
}]
},
options: {
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: 'X Values'
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Y Values'
}
}]
}
}
});
}
</script>
</body>
</html>