-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemo.html
More file actions
233 lines (203 loc) · 14.7 KB
/
memo.html
File metadata and controls
233 lines (203 loc) · 14.7 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example-1-basic</title>
<style>
/* From extension vscode.github */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.vscode-dark img[src$=\#gh-light-mode-only],
.vscode-light img[src$=\#gh-dark-mode-only] {
display: none;
}
/* From extension bierner.markdown-checkbox */
.contains-task-list {
padding-left: 0;
}
.contains-task-list li {
margin-left: 24px;
}
.contains-task-list .task-list-item {
list-style: none;
padding-left: 0;
margin-left: 0;
}
.contains-task-list .contains-task-list {
padding-left: 20px;
}
/* From extension tsutsu3.markdown-named-codeblocks */
.named-fence-block {
position: relative;
padding-top: 2em !important;
}
.named-fence-filename {
position: absolute;
top: 0;
left: 0;
padding: 0 4px;
font-weight: bold;
color: #000000;
background: #c0c0c0;
opacity: 0.6;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Microsoft/vscode/extensions/markdown-language-features/media/highlight.css">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
</style>
<style>
.task-list-item {
list-style-type: none;
}
.task-list-item-checkbox {
margin-left: -20px;
vertical-align: middle;
pointer-events: none;
}
</style>
</head>
<body class="vscode-body vscode-light">
<ul>
<li><a href="#example-1-basic">example-1-basic</a></li>
<li><a href="#example-2-typing">example-2-typing</a></li>
<li><a href="#example-3-realtime">example-3-realTime</a></li>
</ul>
<h2 id="example-1-basic">example-1-basic</h2>
<pre><code class="language-js"><span class="hljs-comment">// グラフのデータ</span>
<span class="hljs-keyword">var</span> data = {
<span class="hljs-attr">labels</span>: [<span class="hljs-string">'A'</span>, <span class="hljs-string">'B'</span>, <span class="hljs-string">'C'</span>, <span class="hljs-string">'D'</span>, <span class="hljs-string">'E'</span>],
<span class="hljs-attr">datasets</span>: [{
<span class="hljs-attr">label</span>: <span class="hljs-string">'Sample Data'</span>,
<span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>],
<span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>, <span class="hljs-comment">// バーの背景色</span>
<span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>, <span class="hljs-comment">// バーの境界線の色</span>
<span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span> <span class="hljs-comment">// バーの境界線の太さ</span>
}]
};
<span class="hljs-comment">// グラフのオプション</span>
<span class="hljs-keyword">var</span> options = {
<span class="hljs-attr">scales</span>: {
<span class="hljs-attr">y</span>: {
<span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
}
}
};
<span class="hljs-comment">// グラフを描画するキャンバス要素を取得</span>
<span class="hljs-keyword">var</span> ctx = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'myChart'</span>).<span class="hljs-title function_">getContext</span>(<span class="hljs-string">'2d'</span>);
<span class="hljs-comment">// 棒グラフを描画</span>
<span class="hljs-keyword">var</span> myChart = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Chart</span>(ctx, {
<span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>, <span class="hljs-comment">// グラフの種類を指定</span>
<span class="hljs-attr">data</span>: data, <span class="hljs-comment">// データ</span>
<span class="hljs-attr">options</span>: options <span class="hljs-comment">// オプション</span>
});
</code></pre>
<h2 id="example-2-typing">example-2-typing</h2>
<pre><code class="language-html"><span class="hljs-tag"><<span class="hljs-name">body</span>></span>
<span class="hljs-comment"><!-- グラフを描画するキャンバス要素 --></span>
<span class="hljs-tag"><<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"progressChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>></span><span class="hljs-tag"></<span class="hljs-name">canvas</span>></span>
<span class="hljs-tag"><<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"errorChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>></span><span class="hljs-tag"></<span class="hljs-name">canvas</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="language-javascript">
<span class="hljs-comment">// 進捗のデータ</span>
<span class="hljs-keyword">var</span> progressData = {
<span class="hljs-attr">labels</span>: [<span class="hljs-string">'Session 1'</span>, <span class="hljs-string">'Session 2'</span>, <span class="hljs-string">'Session 3'</span>, <span class="hljs-string">'Session 4'</span>],
<span class="hljs-attr">datasets</span>: [{
<span class="hljs-attr">label</span>: <span class="hljs-string">'Typing Speed'</span>,
<span class="hljs-attr">data</span>: [<span class="hljs-number">50</span>, <span class="hljs-number">55</span>, <span class="hljs-number">60</span>, <span class="hljs-number">65</span>], <span class="hljs-comment">// WPM (Words Per Minute)</span>
<span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
<span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">fill</span>: <span class="hljs-literal">false</span>
}]
};
<span class="hljs-comment">// ミスタイプのデータ</span>
<span class="hljs-keyword">var</span> errorData = {
<span class="hljs-attr">labels</span>: [<span class="hljs-string">'Session 1'</span>, <span class="hljs-string">'Session 2'</span>, <span class="hljs-string">'Session 3'</span>, <span class="hljs-string">'Session 4'</span>],
<span class="hljs-attr">datasets</span>: [{
<span class="hljs-attr">label</span>: <span class="hljs-string">'Error Rate'</span>,
<span class="hljs-attr">data</span>: [<span class="hljs-number">5</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>], <span class="hljs-comment">// ミスタイプの割合</span>
<span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
<span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
<span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>
}]
};
<span class="hljs-comment">// 進捗のグラフを描画</span>
<span class="hljs-keyword">var</span> progressCtx = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'progressChart'</span>).<span class="hljs-title function_">getContext</span>(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> progressChart = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Chart</span>(progressCtx, {
<span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
<span class="hljs-attr">data</span>: progressData,
<span class="hljs-attr">options</span>: {
<span class="hljs-attr">scales</span>: {
<span class="hljs-attr">y</span>: {
<span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
}
}
}
});
<span class="hljs-comment">// ミスタイプのグラフを描画</span>
<span class="hljs-keyword">var</span> errorCtx = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'errorChart'</span>).<span class="hljs-title function_">getContext</span>(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> errorChart = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Chart</span>(errorCtx, {
<span class="hljs-attr">type</span>: <span class="hljs-string">'pie'</span>,
<span class="hljs-attr">data</span>: errorData
});
</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
</code></pre>
<h2 id="example-3-realtime">example-3-realTime</h2>
<pre><code class="language-html"> <span class="hljs-tag"><<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"realTimeChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>></span><span class="hljs-tag"></<span class="hljs-name">canvas</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="language-javascript">
<span class="hljs-keyword">var</span> ctx = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">'realTimeChart'</span>).<span class="hljs-title function_">getContext</span>(<span class="hljs-string">'2d'</span>);
<span class="hljs-comment">// 初期データ</span>
<span class="hljs-keyword">var</span> initialData = {
<span class="hljs-attr">labels</span>: [],
<span class="hljs-attr">datasets</span>: [{
<span class="hljs-attr">label</span>: <span class="hljs-string">'Real-time Data'</span>,
<span class="hljs-attr">data</span>: [],
<span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
<span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>,
<span class="hljs-attr">fill</span>: <span class="hljs-literal">false</span>
}]
};
<span class="hljs-keyword">var</span> options = {
<span class="hljs-attr">scales</span>: {
<span class="hljs-attr">x</span>: {
<span class="hljs-attr">type</span>: <span class="hljs-string">'linear'</span>,
<span class="hljs-attr">position</span>: <span class="hljs-string">'bottom'</span>
},
<span class="hljs-attr">y</span>: {
<span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
}
}
};
<span class="hljs-keyword">var</span> realTimeChart = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Chart</span>(ctx, {
<span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
<span class="hljs-attr">data</span>: initialData,
<span class="hljs-attr">options</span>: options
});
<span class="hljs-comment">// リアルタイムデータ更新</span>
<span class="hljs-built_in">setInterval</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-keyword">var</span> newDataPoint = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">floor</span>(<span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>() * <span class="hljs-number">100</span>);
<span class="hljs-keyword">var</span> newData = {
<span class="hljs-attr">x</span>: realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">labels</span>.<span class="hljs-property">length</span>,
<span class="hljs-attr">y</span>: newDataPoint
};
<span class="hljs-comment">// データ追加</span>
realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">labels</span>.<span class="hljs-title function_">push</span>(newData.<span class="hljs-property">x</span>);
realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">datasets</span>[<span class="hljs-number">0</span>].<span class="hljs-property">data</span>.<span class="hljs-title function_">push</span>(newData.<span class="hljs-property">y</span>);
<span class="hljs-comment">// データ数が一定以上になったら先頭のデータを削除</span>
<span class="hljs-keyword">if</span> (realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">labels</span>.<span class="hljs-property">length</span> > <span class="hljs-number">10</span>) {
realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">labels</span>.<span class="hljs-title function_">shift</span>();
realTimeChart.<span class="hljs-property">data</span>.<span class="hljs-property">datasets</span>[<span class="hljs-number">0</span>].<span class="hljs-property">data</span>.<span class="hljs-title function_">shift</span>();
}
<span class="hljs-comment">// グラフの更新</span>
realTimeChart.<span class="hljs-title function_">update</span>();
}, <span class="hljs-number">1000</span>); <span class="hljs-comment">// 1秒ごとに更新</span>
</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
</code></pre>
</body>
</html>