{"id":971,"date":"2024-06-30T13:57:26","date_gmt":"2024-06-30T05:57:26","guid":{"rendered":"http:\/\/tamanegi.xyz\/?p=971"},"modified":"2024-06-30T13:57:26","modified_gmt":"2024-06-30T05:57:26","slug":"obsidian-dataviewjs-%e7%bb%98%e5%88%b6%e6%8a%98%e7%ba%bf%e5%9b%be","status":"publish","type":"post","link":"http:\/\/tamanegi.xyz\/?p=971","title":{"rendered":"Obsidian-DataviewJS \u7ed8\u5236\u6298\u7ebf\u56fe"},"content":{"rendered":"<pre><code class=\"language-DataviewJS\">const targetDate = new Date(&quot;2024-06-27&quot;);\nconst files = app.vault.getMarkdownFiles().filter(file =&gt;  {\nreturn file.name.split(&#039; &#039;)[0] &gt;= &quot;2024-06-27&quot; &amp;&amp; file.path.includes(&quot;D01-\u65e5\u8bb0\/2024&quot;); }\n)\nlet data=[];\nfor(let file of files){\n    let content = await app.vault.read(app.vault.getAbstractFileByPath(file.path));\n    const weightLine = content.match(\/\u4f53\u91cd:(\\d+\\.\\d+)\/);\n            console.log(&quot;\u68c0\u67e5\u4f53\u91cd\u83b7\u53d6&quot;,weightLine);\n            if (weightLine) {\n                const weight = parseFloat(weightLine[1]);\n                data.push({ date: file.name.substring(0, 10), weight: weight });\n            }\n}\n\n data.sort((a, b) =&gt; new Date(a.date) - new Date(b.date));\n\n    \/\/ \u51c6\u5907\u7ed8\u56fe\u6570\u636e\n    const dates = data.map(d =&gt; d.date);\n    const weights = data.map(d =&gt; d.weight);\n\n    \/\/ \u4f7f\u7528Plotly\u7ed8\u5236\u6298\u7ebf\u56fe\n    const trace = {\n        x: dates,\n        y: weights,\n        type: &#039;scatter&#039;,\n        mode: &#039;lines+markers+text&#039;,\n        marker: { color: &#039;blue&#039; },\n        text: weights.map(weight =&gt; `${weight} kg`), \/\/ \u6620\u5c04weights\u6570\u7ec4\u5230\u6587\u672c\uff0c\u6dfb\u52a0\u5355\u4f4d \n        textposition: &#039;top center&#039; \/\/ \u8bbe\u7f6e\u6587\u672c\u7684\u4f4d\u7f6e\n    };\n    console.log(&quot;trace&quot;,trace);\n\n    const layout = {\n        title: &#039;\u4f53\u91cd\u53d8\u5316\u6298\u7ebf\u56fe&#039;,\n        xaxis: { title: &#039;\u65e5\u671f&#039; },\n        yaxis: { title: &#039;\u4f53\u91cd (kg)&#039; }\n    };\n    window.renderPlotly(this.container,[trace], layout);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>const targetDate = new Date(&quot;2024-06-27&quot;); co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110,11],"tags":[],"_links":{"self":[{"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/posts\/971"}],"collection":[{"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=971"}],"version-history":[{"count":1,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/posts\/971\/revisions"}],"predecessor-version":[{"id":972,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=\/wp\/v2\/posts\/971\/revisions\/972"}],"wp:attachment":[{"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=971"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tamanegi.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}