{"id":600,"date":"2017-07-18T15:53:27","date_gmt":"2017-07-18T06:53:27","guid":{"rendered":"https:\/\/www.amano-labo.jp\/pages\/?p=600"},"modified":"2017-07-18T15:53:27","modified_gmt":"2017-07-18T06:53:27","slug":"node-js-express%e7%92%b0%e5%a2%83%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8bchart-js%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9","status":"publish","type":"post","link":"https:\/\/www.amano-labo.jp\/pages\/tips\/600\/","title":{"rendered":"node.js + Express\u74b0\u5883\u306b\u304a\u3051\u308bchart.js\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"<div class=\"amano- amano-entity-placement\" id=\"amano-803006609\"><div id=\"amano-1465322827\"><a href=\"https:\/\/www.amazon.co.jp\/dp\/4274222640\/ref=cm_sw_r_cp_ep_dp_RK1JBb6W0ZSQ5\" aria-label=\"iotbook201809\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809.png\" alt=\"\"  srcset=\"https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809.png 1000w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-300x24.png 300w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-768x61.png 768w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-100x8.png 100w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-150x12.png 150w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-200x16.png 200w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-450x36.png 450w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-600x48.png 600w, https:\/\/www.amano-labo.jp\/pages\/wp-content\/uploads\/2018\/06\/iotbook201809-900x72.png 900w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" width=\"1000\" height=\"80\"   \/><\/a><\/div><\/div><p>\u5148\u65e5\u3001\u3042\u308b\u30b7\u30b9\u30c6\u30e0\u306b\u30b0\u30e9\u30d5\u63cf\u753b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u30b7\u30b9\u30c6\u30e0\u81ea\u4f53\u306fnode.js + Express\u306a\u74b0\u5883\u3067\u3057\u305f\u306e\u3067\u3001\u3053\u308c\u306bchart.js\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u79c1\u304cnode.js\u3092\u3088\u304f\u7406\u89e3\u3057\u3066\u3044\u306a\u3044\u305f\u3081\u3067\u3059\u304c\u3001\u8abf\u3079\u3066\u3082\u3053\u306e\u7d44\u307f\u5408\u308f\u305b\u3060\u3068\u3042\u307e\u308a\u4f8b\u304c\u51fa\u3066\u304d\u307e\u305b\u3093\u3002\u672c\u6765\u306f\u7279\u306b\u3053\u306e\u74b0\u5883\u306b\u7279\u5316\u3057\u305f\u90e8\u5206\u306f\u307b\u3068\u3093\u3069\u306a\u3044\u3088\u3046\u3067\u3059\u304c\u3001\u5f53\u3066\u306f\u3081\u306b\u4e00\u65e5\u6642\u9593\u3092\u304b\u3051\u3066\u7406\u89e3\u3057\u305f\u306e\u3067\u3001\u30e1\u30e2\u304c\u3066\u3089\u8a18\u4e8b\u5316\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>[routes]<br \/>\n\u4e00\u822c\u7684\u306a\u69cb\u6210\u3067\u306f\u3001routes\/index.js\u304cMVC\u3067\u3044\u3046\u3068\u3053\u308d\u306eC\u306b\u3042\u305f\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u79c1\u306f\u3053\u3053\u3067\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306fJSON\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u3068\u3044\u3046\u524d\u63d0\u3067\u3057\u305f\u306e\u3067\u3001\u3053\u3053\u304b\u30891\u884c\u305a\u3064\u8aad\u307f\u8fbc\u3093\u3067\u51e6\u7406\u3057\u307e\u3059\u3002node.js\u3067\u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\u3092\u8abf\u3079\u308b\u3068\u975e\u540c\u671f\u51e6\u7406\u306e\u4f8b\u304c\u305f\u304f\u3055\u3093\u51fa\u3066\u304d\u3066\u3053\u308c\u307e\u305f\u56f0\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u3053\u3067\u306f\u300cn-readlines\u300d\u3068\u3044\u3046\u7d20\u6674\u3089\u3057\u3044\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u305f\u3069\u308a\u7740\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u304a\u304a\u3088\u305d\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u69cb\u9020\u3067\u3059\u3002<\/p>\n<p>var nreadlines = require(&#8216;n-readlines&#8217;);<br \/>\n&#8230;<br \/>\nrouter.get(&#8216;\/?????&#8217;, function (request, response) {<br \/>\ndataList = new Array();<br \/>\nvar liner = new nreadlines(&#8216;\u30d5\u30a1\u30a4\u30eb\u540d&#8217;);<br \/>\nvar line;<br \/>\nwhile (line = liner.next()) {<br \/>\nvar data = JSON.parse(line);<br \/>\n&#8230;.<br \/>\ndataList.push( { x:???, y:??? } );<br \/>\n}<br \/>\nresponse.render(&#8216;?????&#8217;, { dataList:dataLust });<br \/>\n});<\/p>\n<p>[views]<br \/>\n\u79c1\u306f\u30b0\u30e9\u30d5\u63cf\u753b\u7528\u306e\u753b\u9762\u3092\u4e00\u3064\u7528\u610f\u3059\u308b\u3053\u3068\u306b\u3057\u305f\u306e\u3067\u3001views\/graph.ejs\u306e\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u8eab\u306f\u304a\u304a\u3088\u305d\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>&lt;head&gt;<br \/>\n&#8230;.<br \/>\n&lt;script src=&#8221;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/Chart.js\/2.3.0\/Chart.min.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&#8230;.<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;canvas id=&#8221;myChart&#8221; width=&#8221;400&#8243; height=&#8221;300&#8243;&gt;&lt;\/canvas&gt;<br \/>\n&lt;script&gt;<br \/>\nvar dataList = &lt;%- JSON.stringify(dataList) %&gt;;<br \/>\nvar ctx = document.getElementById(&#8216;myChart&#8217;).getContext(&#8216;2d&#8217;);<br \/>\nvar myChart = new Chart(ctx, {<br \/>\ndata: {<br \/>\ndatasets: [{<br \/>\ntype: &#8216;line&#8217;,<br \/>\nlabel: &#8216;data&#8217;,<br \/>\nfill: false,<br \/>\ndata: dataList,<br \/>\nborderColor: &#8220;rgba(0,0,0,0)&#8221;,<br \/>\nbackgroundColor: &#8220;rgba(255,150,0.9)&#8221;<br \/>\n}]<br \/>\n},<br \/>\noptions: {<br \/>\nscales: {<br \/>\nxAxes: [{<br \/>\ntype: &#8216;linear&#8217;,<br \/>\nposition: &#8216;bottom&#8217;,<br \/>\nscaleLabel: {<br \/>\ndisplay: true,<br \/>\nlabelString: &#8216;xlabel&#8217;<br \/>\n},<br \/>\nticks: {<br \/>\nmin: 0,<br \/>\nmax: 1000,<br \/>\nstepSize: 100<br \/>\n}<br \/>\n}],<br \/>\nyAxes: [{<br \/>\ntype: &#8220;linear&#8221;,<br \/>\nscaleLabel: {<br \/>\ndisplay: true,<br \/>\nlabelString: &#8216;y&#8217;<br \/>\n},<br \/>\nticks: {<br \/>\n}<br \/>\n}]<br \/>\n}<br \/>\n}<br \/>\n});<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5\u3001\u3042\u308b\u30b7\u30b9\u30c6\u30e0\u306b\u30b0\u30e9\u30d5\u63cf\u753b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u30b7\u30b9\u30c6\u30e0\u81ea\u4f53\u306fnode.js + Express\u306a\u74b0\u5883\u3067\u3057\u305f\u306e\u3067\u3001\u3053\u308c\u306bchart.js\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002 \u79c1\u304cnode.js\u3092\u3088\u304f\u7406\u89e3\u3057\u3066\u3044\u306a\u3044\u305f\u3081 <a class=\"more-link\" href=\"https:\/\/www.amano-labo.jp\/pages\/tips\/600\/\">\u7d9a\u304d\u3092\u8aad\u3080\u2026<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6,4],"tags":[19,20],"class_list":["post-600","post","type-post","status-publish","format-standard","hentry","category-software","category-tips","tag-javascript","tag-node-js"],"_links":{"self":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/comments?post=600"}],"version-history":[{"count":0,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/posts\/600\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/media?parent=600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/categories?post=600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amano-labo.jp\/pages\/wp-json\/wp\/v2\/tags?post=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}