-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathlineChart.html
More file actions
211 lines (207 loc) · 7.62 KB
/
lineChart.html
File metadata and controls
211 lines (207 loc) · 7.62 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Line Chart - Chart.js Trendline Plugin</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.5.0/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 40px 20px;
background-color: #f8f9fa;
color: #333;
line-height: 1.6;
}
.container {
max-width: 1000px;
margin: 0 auto;
}
h1 {
text-align: center;
color: #2c3e50;
margin-bottom: 10px;
font-size: 2.5rem;
}
.subtitle {
text-align: center;
color: #7f8c8d;
margin-bottom: 40px;
font-size: 1.1rem;
}
.chart-container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.chart-wrapper {
position: relative;
height: 400px;
}
.info-section {
background: white;
padding: 25px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.info-section h3 {
margin-top: 0;
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 10px;
}
.nav-links {
text-align: center;
margin-top: 30px;
}
.nav-links a {
display: inline-block;
margin: 0 10px;
padding: 10px 20px;
background: #3498db;
color: white;
text-decoration: none;
border-radius: 4px;
font-weight: 500;
transition: background-color 0.2s;
}
.nav-links a:hover {
background: #2980b9;
}
code {
background: #f8f9fa;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', monospace;
}
</style>
</head>
<body>
<div class="container">
<h1>Line Chart with Labeled Trendlines</h1>
<p class="subtitle">Multiple datasets with different trendline styles and custom labels</p>
<div class="chart-container">
<div class="chart-wrapper">
<canvas id="line-chart"></canvas>
</div>
</div>
<div class="info-section">
<h3>Configuration Features</h3>
<p>This example demonstrates advanced trendline features on line chart data:</p>
<ul>
<li><strong>Multiple datasets:</strong> Each with unique trendline configurations</li>
<li><strong>Custom labels:</strong> Asia dataset shows custom label positioning with offset</li>
<li><strong>Legend integration:</strong> Custom legend text for trendlines</li>
<li><strong>Line styles:</strong> Solid, dashed, and dotted trendlines</li>
<li><strong>Color gradients:</strong> Asia trendline uses colorMin/colorMax for gradient effect</li>
</ul>
</div>
<div class="nav-links">
<a href="../index.html">← Back to Examples</a>
<a href="barChartWithNullValues.html">← Bar Chart with Null Values</a>
<a href="lineChartProjection.html">Line Chart Projection →</a>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function (event) {
new Chart(document.getElementById('line-chart'), {
type: 'line',
data: {
labels: [
1500, 1600, 1700, 1750, 1800, 1850, 1900, 1950,
1999, 2050,
],
datasets: [
{
data: [
86, 114, 106, 106, 107, 111, 133, 221, 783,
2478,
],
label: 'Africa',
borderColor: '#3e95cd',
fill: false,
trendlineLinear: {
colorMin: '#3e95cd',
width: 1,
lineStyle: 'solid',
},
},
{
data: [
282, 350, 411, 502, 635, 809, 947, 1402,
3700, 5267,
],
label: 'Asia',
borderColor: '#8e5ea2',
fill: false,
trendlineLinear: {
colorMin: 'red',
colorMax: 'green',
lineStyle: 'dashed',
width: 1,
label: {
font: {
size: 12,
},
color: 'red',
text: 'Asia',
displayValue: false,
offset: 10,
},
legend: {
color: 'red',
text: 'Asian trendline',
display: true,
lineDash: [8, 3],
},
},
},
{
data: [
168, 170, 178, 190, 203, 276, 408, 547, 675,
734,
],
label: 'Europe',
borderColor: '#3cba9f',
fill: false,
},
{
data: [
40, 20, 10, 16, 24, 38, 74, 167, 508, 784,
],
label: 'Latin America',
borderColor: '#e8c3b9',
fill: false,
},
{
data: [6, 3, 2, 2, 7, 26, 82, 172, 312, 433],
label: 'North America',
borderColor: '#c45850',
fill: false,
},
],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'World population per region (in millions)',
font: {
size: 16
}
},
},
},
});
});
</script>
</body>
</html>