chartjs-plugin-trendline 3.2.0 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +40 -40
- package/.github/workflows/release.yml +64 -61
- package/.github/workflows/tests.yml +26 -26
- package/.prettierrc +5 -5
- package/CLAUDE.md +44 -44
- package/GEMINI.md +40 -40
- package/LICENSE +21 -21
- package/MIGRATION.md +126 -126
- package/README.md +166 -166
- package/babel.config.js +3 -3
- package/changelog.md +39 -39
- package/dist/chartjs-plugin-trendline.cjs +884 -885
- package/dist/chartjs-plugin-trendline.esm.js +882 -883
- package/dist/chartjs-plugin-trendline.js +890 -891
- package/dist/chartjs-plugin-trendline.min.js +8 -8
- package/dist/chartjs-plugin-trendline.min.js.map +1 -1
- package/example/barChart.html +165 -165
- package/example/barChartWithNullValues.html +168 -168
- package/example/barChart_label.html +174 -174
- package/example/exponentialChart.html +244 -244
- package/example/lineChart.html +210 -210
- package/example/lineChartProjection.html +261 -261
- package/example/lineChartTypeTime.html +190 -190
- package/example/scatterChart.html +136 -136
- package/example/scatterProjection.html +141 -141
- package/example/test-null-handling.html +59 -59
- package/index.html +215 -215
- package/jest.config.js +4 -4
- package/package.json +45 -40
- package/rollup.config.js +54 -54
- package/src/components/label.js +56 -56
- package/src/components/label.test.js +129 -129
- package/src/components/trendline.js +375 -375
- package/src/components/trendline.test.js +789 -789
- package/src/core/plugin.js +78 -79
- package/src/core/plugin.test.js +307 -0
- package/src/index.js +12 -12
- package/src/utils/drawing.js +125 -125
- package/src/utils/drawing.test.js +308 -308
- package/src/utils/exponentialFitter.js +146 -146
- package/src/utils/exponentialFitter.test.js +362 -362
- package/src/utils/lineFitter.js +86 -86
- package/src/utils/lineFitter.test.js +340 -340
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Time Scale Line Chart - Chart.js Trendline Plugin</title>
|
|
7
|
-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
8
|
-
<!-- Include Chart.js and the Trendline plugin -->
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
10
|
-
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
12
|
-
<style>
|
|
13
|
-
body {
|
|
14
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
15
|
-
margin: 0;
|
|
16
|
-
padding: 40px 20px;
|
|
17
|
-
background-color: #f8f9fa;
|
|
18
|
-
color: #333;
|
|
19
|
-
line-height: 1.6;
|
|
20
|
-
}
|
|
21
|
-
.container {
|
|
22
|
-
max-width: 1000px;
|
|
23
|
-
margin: 0 auto;
|
|
24
|
-
}
|
|
25
|
-
h1 {
|
|
26
|
-
text-align: center;
|
|
27
|
-
color: #2c3e50;
|
|
28
|
-
margin-bottom: 10px;
|
|
29
|
-
font-size: 2.5rem;
|
|
30
|
-
}
|
|
31
|
-
.subtitle {
|
|
32
|
-
text-align: center;
|
|
33
|
-
color: #7f8c8d;
|
|
34
|
-
margin-bottom: 40px;
|
|
35
|
-
font-size: 1.1rem;
|
|
36
|
-
}
|
|
37
|
-
.chart-container {
|
|
38
|
-
background: white;
|
|
39
|
-
padding: 30px;
|
|
40
|
-
border-radius: 8px;
|
|
41
|
-
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
42
|
-
margin-bottom: 30px;
|
|
43
|
-
}
|
|
44
|
-
.chart-wrapper {
|
|
45
|
-
position: relative;
|
|
46
|
-
height: 400px;
|
|
47
|
-
}
|
|
48
|
-
</style>
|
|
49
|
-
</head>
|
|
50
|
-
<body>
|
|
51
|
-
<div class="container">
|
|
52
|
-
<h1>Chart.js Trendline Plugin</h1>
|
|
53
|
-
<p class="subtitle">Time Scale Line Chart with Trendline</p>
|
|
54
|
-
|
|
55
|
-
<div class="chart-container">
|
|
56
|
-
<div class="chart-wrapper">
|
|
57
|
-
<canvas id="chartjs"></canvas>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
|
|
62
|
-
<script type="text/javascript">
|
|
63
|
-
// Get the context of the canvas element we want to select
|
|
64
|
-
const ctx = document.getElementById("chartjs").getContext('2d');
|
|
65
|
-
|
|
66
|
-
const chartDynamics = [
|
|
67
|
-
{
|
|
68
|
-
datepost: "2025-03-01T00:00:00",
|
|
69
|
-
quantity: 75,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
datepost: "2025-03-02T00:00:00",
|
|
73
|
-
quantity: 64,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
datepost: "2025-03-03T00:00:00",
|
|
77
|
-
quantity: 52,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
datepost: "2025-03-04T00:00:00",
|
|
81
|
-
quantity: 23,
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
datepost: "2025-03-05T00:00:00",
|
|
85
|
-
quantity: 44,
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
datepost: "2025-03-06T00:00:00",
|
|
89
|
-
quantity: 38,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
datepost: "2025-03-07T00:00:00",
|
|
93
|
-
quantity: 44,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
datepost: "2025-03-08T00:00:00",
|
|
97
|
-
quantity: 41,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
datepost: "2025-03-09T00:00:00",
|
|
101
|
-
quantity: 78,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
datepost: "2025-03-10T00:00:00",
|
|
105
|
-
quantity: 31,
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
// Create a new Chart instance
|
|
110
|
-
const myChart1 = new Chart(ctx, {
|
|
111
|
-
type: "line",
|
|
112
|
-
data: {
|
|
113
|
-
labels: chartDynamics.map((o) => o.datepost),
|
|
114
|
-
datasets: [
|
|
115
|
-
{
|
|
116
|
-
label: "Daily Quantity",
|
|
117
|
-
data: chartDynamics.map((o) => o.quantity),
|
|
118
|
-
borderColor: '#3e95cd',
|
|
119
|
-
backgroundColor: 'rgba(62,149,205,0.1)',
|
|
120
|
-
borderWidth: 2,
|
|
121
|
-
pointStyle: 'circle',
|
|
122
|
-
pointRadius: 4,
|
|
123
|
-
pointHoverRadius: 6,
|
|
124
|
-
fill: false,
|
|
125
|
-
trendlineLinear: {
|
|
126
|
-
colorMin: '#e74c3c',
|
|
127
|
-
lineStyle: "dotted",
|
|
128
|
-
width: 2,
|
|
129
|
-
label: {
|
|
130
|
-
display: true,
|
|
131
|
-
text: "Trend",
|
|
132
|
-
displayValue: true
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
options: {
|
|
139
|
-
maintainAspectRatio: false,
|
|
140
|
-
responsive: true,
|
|
141
|
-
plugins: {
|
|
142
|
-
title: {
|
|
143
|
-
display: true,
|
|
144
|
-
text: 'Time Series Data with Linear Trendline',
|
|
145
|
-
font: { size: 16 }
|
|
146
|
-
},
|
|
147
|
-
legend: {
|
|
148
|
-
display: true,
|
|
149
|
-
position: 'top'
|
|
150
|
-
},
|
|
151
|
-
tooltip: {
|
|
152
|
-
mode: 'index',
|
|
153
|
-
intersect: false
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
scales: {
|
|
157
|
-
x: {
|
|
158
|
-
type: "time",
|
|
159
|
-
time: {
|
|
160
|
-
tooltipFormat: "MMM d, yyyy",
|
|
161
|
-
displayFormats: {
|
|
162
|
-
day: 'MMM d'
|
|
163
|
-
},
|
|
164
|
-
minUnit: "day"
|
|
165
|
-
},
|
|
166
|
-
title: {
|
|
167
|
-
display: true,
|
|
168
|
-
text: 'Date'
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
y: {
|
|
172
|
-
title: {
|
|
173
|
-
display: true,
|
|
174
|
-
text: 'Quantity'
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
interaction: { mode: "nearest", intersect: false }
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
</script>
|
|
183
|
-
|
|
184
|
-
<div style="text-align: center; margin-top: 30px;">
|
|
185
|
-
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
186
|
-
<a href="lineChartProjection.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Line Chart Projection</a>
|
|
187
|
-
<a href="scatterChart.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">Scatter Chart →</a>
|
|
188
|
-
</div>
|
|
189
|
-
|
|
190
|
-
</body>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Time Scale Line Chart - Chart.js Trendline Plugin</title>
|
|
7
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
8
|
+
<!-- Include Chart.js and the Trendline plugin -->
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
10
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
12
|
+
<style>
|
|
13
|
+
body {
|
|
14
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 40px 20px;
|
|
17
|
+
background-color: #f8f9fa;
|
|
18
|
+
color: #333;
|
|
19
|
+
line-height: 1.6;
|
|
20
|
+
}
|
|
21
|
+
.container {
|
|
22
|
+
max-width: 1000px;
|
|
23
|
+
margin: 0 auto;
|
|
24
|
+
}
|
|
25
|
+
h1 {
|
|
26
|
+
text-align: center;
|
|
27
|
+
color: #2c3e50;
|
|
28
|
+
margin-bottom: 10px;
|
|
29
|
+
font-size: 2.5rem;
|
|
30
|
+
}
|
|
31
|
+
.subtitle {
|
|
32
|
+
text-align: center;
|
|
33
|
+
color: #7f8c8d;
|
|
34
|
+
margin-bottom: 40px;
|
|
35
|
+
font-size: 1.1rem;
|
|
36
|
+
}
|
|
37
|
+
.chart-container {
|
|
38
|
+
background: white;
|
|
39
|
+
padding: 30px;
|
|
40
|
+
border-radius: 8px;
|
|
41
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
42
|
+
margin-bottom: 30px;
|
|
43
|
+
}
|
|
44
|
+
.chart-wrapper {
|
|
45
|
+
position: relative;
|
|
46
|
+
height: 400px;
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
51
|
+
<div class="container">
|
|
52
|
+
<h1>Chart.js Trendline Plugin</h1>
|
|
53
|
+
<p class="subtitle">Time Scale Line Chart with Trendline</p>
|
|
54
|
+
|
|
55
|
+
<div class="chart-container">
|
|
56
|
+
<div class="chart-wrapper">
|
|
57
|
+
<canvas id="chartjs"></canvas>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<script type="text/javascript">
|
|
63
|
+
// Get the context of the canvas element we want to select
|
|
64
|
+
const ctx = document.getElementById("chartjs").getContext('2d');
|
|
65
|
+
|
|
66
|
+
const chartDynamics = [
|
|
67
|
+
{
|
|
68
|
+
datepost: "2025-03-01T00:00:00",
|
|
69
|
+
quantity: 75,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
datepost: "2025-03-02T00:00:00",
|
|
73
|
+
quantity: 64,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
datepost: "2025-03-03T00:00:00",
|
|
77
|
+
quantity: 52,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
datepost: "2025-03-04T00:00:00",
|
|
81
|
+
quantity: 23,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
datepost: "2025-03-05T00:00:00",
|
|
85
|
+
quantity: 44,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
datepost: "2025-03-06T00:00:00",
|
|
89
|
+
quantity: 38,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
datepost: "2025-03-07T00:00:00",
|
|
93
|
+
quantity: 44,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
datepost: "2025-03-08T00:00:00",
|
|
97
|
+
quantity: 41,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
datepost: "2025-03-09T00:00:00",
|
|
101
|
+
quantity: 78,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
datepost: "2025-03-10T00:00:00",
|
|
105
|
+
quantity: 31,
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
// Create a new Chart instance
|
|
110
|
+
const myChart1 = new Chart(ctx, {
|
|
111
|
+
type: "line",
|
|
112
|
+
data: {
|
|
113
|
+
labels: chartDynamics.map((o) => o.datepost),
|
|
114
|
+
datasets: [
|
|
115
|
+
{
|
|
116
|
+
label: "Daily Quantity",
|
|
117
|
+
data: chartDynamics.map((o) => o.quantity),
|
|
118
|
+
borderColor: '#3e95cd',
|
|
119
|
+
backgroundColor: 'rgba(62,149,205,0.1)',
|
|
120
|
+
borderWidth: 2,
|
|
121
|
+
pointStyle: 'circle',
|
|
122
|
+
pointRadius: 4,
|
|
123
|
+
pointHoverRadius: 6,
|
|
124
|
+
fill: false,
|
|
125
|
+
trendlineLinear: {
|
|
126
|
+
colorMin: '#e74c3c',
|
|
127
|
+
lineStyle: "dotted",
|
|
128
|
+
width: 2,
|
|
129
|
+
label: {
|
|
130
|
+
display: true,
|
|
131
|
+
text: "Trend",
|
|
132
|
+
displayValue: true
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
options: {
|
|
139
|
+
maintainAspectRatio: false,
|
|
140
|
+
responsive: true,
|
|
141
|
+
plugins: {
|
|
142
|
+
title: {
|
|
143
|
+
display: true,
|
|
144
|
+
text: 'Time Series Data with Linear Trendline',
|
|
145
|
+
font: { size: 16 }
|
|
146
|
+
},
|
|
147
|
+
legend: {
|
|
148
|
+
display: true,
|
|
149
|
+
position: 'top'
|
|
150
|
+
},
|
|
151
|
+
tooltip: {
|
|
152
|
+
mode: 'index',
|
|
153
|
+
intersect: false
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
scales: {
|
|
157
|
+
x: {
|
|
158
|
+
type: "time",
|
|
159
|
+
time: {
|
|
160
|
+
tooltipFormat: "MMM d, yyyy",
|
|
161
|
+
displayFormats: {
|
|
162
|
+
day: 'MMM d'
|
|
163
|
+
},
|
|
164
|
+
minUnit: "day"
|
|
165
|
+
},
|
|
166
|
+
title: {
|
|
167
|
+
display: true,
|
|
168
|
+
text: 'Date'
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
y: {
|
|
172
|
+
title: {
|
|
173
|
+
display: true,
|
|
174
|
+
text: 'Quantity'
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
interaction: { mode: "nearest", intersect: false }
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<div style="text-align: center; margin-top: 30px;">
|
|
185
|
+
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
186
|
+
<a href="lineChartProjection.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Line Chart Projection</a>
|
|
187
|
+
<a href="scatterChart.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">Scatter Chart →</a>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
</body>
|
|
191
191
|
</html>
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
-
<title>Scatter Chart - Chart.js Trendline Plugin</title>
|
|
8
|
-
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
10
|
-
<style>
|
|
11
|
-
body {
|
|
12
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
13
|
-
margin: 0;
|
|
14
|
-
padding: 40px 20px;
|
|
15
|
-
background-color: #f8f9fa;
|
|
16
|
-
color: #333;
|
|
17
|
-
line-height: 1.6;
|
|
18
|
-
}
|
|
19
|
-
.container {
|
|
20
|
-
max-width: 1000px;
|
|
21
|
-
margin: 0 auto;
|
|
22
|
-
}
|
|
23
|
-
h1 {
|
|
24
|
-
text-align: center;
|
|
25
|
-
color: #2c3e50;
|
|
26
|
-
margin-bottom: 10px;
|
|
27
|
-
font-size: 2.5rem;
|
|
28
|
-
}
|
|
29
|
-
.subtitle {
|
|
30
|
-
text-align: center;
|
|
31
|
-
color: #7f8c8d;
|
|
32
|
-
margin-bottom: 40px;
|
|
33
|
-
font-size: 1.1rem;
|
|
34
|
-
}
|
|
35
|
-
.chart-container {
|
|
36
|
-
background: white;
|
|
37
|
-
padding: 30px;
|
|
38
|
-
border-radius: 8px;
|
|
39
|
-
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
40
|
-
margin-bottom: 30px;
|
|
41
|
-
}
|
|
42
|
-
.chart-wrapper {
|
|
43
|
-
position: relative;
|
|
44
|
-
height: 400px;
|
|
45
|
-
}
|
|
46
|
-
</style>
|
|
47
|
-
<script>
|
|
48
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
49
|
-
new Chart(document.getElementById("scatter-chart"), {
|
|
50
|
-
type: 'scatter',
|
|
51
|
-
data: {
|
|
52
|
-
datasets: [
|
|
53
|
-
{
|
|
54
|
-
label: "Sample Data Points",
|
|
55
|
-
data: [
|
|
56
|
-
{x: 12.39, y: 130},
|
|
57
|
-
{x: 12.39, y: 142},
|
|
58
|
-
{x: 11.39, y: 170},
|
|
59
|
-
{x: 13.14, y: 12268},
|
|
60
|
-
{x: 13.14, y: 9947}
|
|
61
|
-
],
|
|
62
|
-
backgroundColor: "#3e95cd",
|
|
63
|
-
borderColor: "#2980b9",
|
|
64
|
-
pointRadius: 6,
|
|
65
|
-
pointHoverRadius: 8,
|
|
66
|
-
trendlineLinear: {
|
|
67
|
-
colorMin: "#e74c3c",
|
|
68
|
-
lineStyle: "dotted",
|
|
69
|
-
width: 2,
|
|
70
|
-
label: {
|
|
71
|
-
display: true,
|
|
72
|
-
text: "Linear Trend",
|
|
73
|
-
displayValue: true
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
]
|
|
78
|
-
},
|
|
79
|
-
options: {
|
|
80
|
-
maintainAspectRatio: false,
|
|
81
|
-
responsive: true,
|
|
82
|
-
plugins: {
|
|
83
|
-
title: {
|
|
84
|
-
display: true,
|
|
85
|
-
text: 'Scatter Plot with Linear Trendline',
|
|
86
|
-
font: { size: 16 }
|
|
87
|
-
},
|
|
88
|
-
legend: {
|
|
89
|
-
display: true,
|
|
90
|
-
position: 'top'
|
|
91
|
-
},
|
|
92
|
-
tooltip: {
|
|
93
|
-
mode: 'point',
|
|
94
|
-
intersect: true
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
scales: {
|
|
98
|
-
x: {
|
|
99
|
-
type: 'linear',
|
|
100
|
-
position: 'bottom',
|
|
101
|
-
title: {
|
|
102
|
-
display: true,
|
|
103
|
-
text: 'X Value'
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
y: {
|
|
107
|
-
title: {
|
|
108
|
-
display: true,
|
|
109
|
-
text: 'Y Value'
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
</script>
|
|
117
|
-
</head>
|
|
118
|
-
<body>
|
|
119
|
-
<div class="container">
|
|
120
|
-
<h1>Chart.js Trendline Plugin</h1>
|
|
121
|
-
<p class="subtitle">Scatter Chart with Linear Trendline</p>
|
|
122
|
-
|
|
123
|
-
<div class="chart-container">
|
|
124
|
-
<div class="chart-wrapper">
|
|
125
|
-
<canvas id="scatter-chart"></canvas>
|
|
126
|
-
</div>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<div style="text-align: center; margin-top: 30px;">
|
|
130
|
-
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
131
|
-
<a href="lineChartTypeTime.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Time Series Line Chart</a>
|
|
132
|
-
<a href="scatterProjection.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">Scatter Projection →</a>
|
|
133
|
-
</div>
|
|
134
|
-
</div>
|
|
135
|
-
</body>
|
|
136
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
7
|
+
<title>Scatter Chart - Chart.js Trendline Plugin</title>
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
|
|
9
|
+
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
|
|
10
|
+
<style>
|
|
11
|
+
body {
|
|
12
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 40px 20px;
|
|
15
|
+
background-color: #f8f9fa;
|
|
16
|
+
color: #333;
|
|
17
|
+
line-height: 1.6;
|
|
18
|
+
}
|
|
19
|
+
.container {
|
|
20
|
+
max-width: 1000px;
|
|
21
|
+
margin: 0 auto;
|
|
22
|
+
}
|
|
23
|
+
h1 {
|
|
24
|
+
text-align: center;
|
|
25
|
+
color: #2c3e50;
|
|
26
|
+
margin-bottom: 10px;
|
|
27
|
+
font-size: 2.5rem;
|
|
28
|
+
}
|
|
29
|
+
.subtitle {
|
|
30
|
+
text-align: center;
|
|
31
|
+
color: #7f8c8d;
|
|
32
|
+
margin-bottom: 40px;
|
|
33
|
+
font-size: 1.1rem;
|
|
34
|
+
}
|
|
35
|
+
.chart-container {
|
|
36
|
+
background: white;
|
|
37
|
+
padding: 30px;
|
|
38
|
+
border-radius: 8px;
|
|
39
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
40
|
+
margin-bottom: 30px;
|
|
41
|
+
}
|
|
42
|
+
.chart-wrapper {
|
|
43
|
+
position: relative;
|
|
44
|
+
height: 400px;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
47
|
+
<script>
|
|
48
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
49
|
+
new Chart(document.getElementById("scatter-chart"), {
|
|
50
|
+
type: 'scatter',
|
|
51
|
+
data: {
|
|
52
|
+
datasets: [
|
|
53
|
+
{
|
|
54
|
+
label: "Sample Data Points",
|
|
55
|
+
data: [
|
|
56
|
+
{x: 12.39, y: 130},
|
|
57
|
+
{x: 12.39, y: 142},
|
|
58
|
+
{x: 11.39, y: 170},
|
|
59
|
+
{x: 13.14, y: 12268},
|
|
60
|
+
{x: 13.14, y: 9947}
|
|
61
|
+
],
|
|
62
|
+
backgroundColor: "#3e95cd",
|
|
63
|
+
borderColor: "#2980b9",
|
|
64
|
+
pointRadius: 6,
|
|
65
|
+
pointHoverRadius: 8,
|
|
66
|
+
trendlineLinear: {
|
|
67
|
+
colorMin: "#e74c3c",
|
|
68
|
+
lineStyle: "dotted",
|
|
69
|
+
width: 2,
|
|
70
|
+
label: {
|
|
71
|
+
display: true,
|
|
72
|
+
text: "Linear Trend",
|
|
73
|
+
displayValue: true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
options: {
|
|
80
|
+
maintainAspectRatio: false,
|
|
81
|
+
responsive: true,
|
|
82
|
+
plugins: {
|
|
83
|
+
title: {
|
|
84
|
+
display: true,
|
|
85
|
+
text: 'Scatter Plot with Linear Trendline',
|
|
86
|
+
font: { size: 16 }
|
|
87
|
+
},
|
|
88
|
+
legend: {
|
|
89
|
+
display: true,
|
|
90
|
+
position: 'top'
|
|
91
|
+
},
|
|
92
|
+
tooltip: {
|
|
93
|
+
mode: 'point',
|
|
94
|
+
intersect: true
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
scales: {
|
|
98
|
+
x: {
|
|
99
|
+
type: 'linear',
|
|
100
|
+
position: 'bottom',
|
|
101
|
+
title: {
|
|
102
|
+
display: true,
|
|
103
|
+
text: 'X Value'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
y: {
|
|
107
|
+
title: {
|
|
108
|
+
display: true,
|
|
109
|
+
text: 'Y Value'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
</head>
|
|
118
|
+
<body>
|
|
119
|
+
<div class="container">
|
|
120
|
+
<h1>Chart.js Trendline Plugin</h1>
|
|
121
|
+
<p class="subtitle">Scatter Chart with Linear Trendline</p>
|
|
122
|
+
|
|
123
|
+
<div class="chart-container">
|
|
124
|
+
<div class="chart-wrapper">
|
|
125
|
+
<canvas id="scatter-chart"></canvas>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<div style="text-align: center; margin-top: 30px;">
|
|
130
|
+
<a href="../index.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Back to Examples</a>
|
|
131
|
+
<a href="lineChartTypeTime.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">← Time Series Line Chart</a>
|
|
132
|
+
<a href="scatterProjection.html" style="display: inline-block; margin: 0 10px; padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 4px; font-weight: 500;">Scatter Projection →</a>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
</body>
|
|
136
|
+
</html>
|