SkyoceanHome
Home
Privacy
ダウンロード
SkyShop
Updated Information
チュートリアルコード集
記事編集
日付
ジャンルのカテゴリ―名
名前を選択して下さい。
Contexts
Controllers
Databases
Htmls
JavaScripts
Models
MVCTutorials
Others
Styles
Views
タイトル
内容の要旨
<p><span style="color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 18px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;" data-pasted="true"><strong>プロジェクトにChart.jsを追加します。</strong></span></p><p><span style="color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 18px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">ページに影響のある<header>に相当する部分にchart.jsを追加します。</span></p><p><span style="color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 18px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">例:プロジェクトの_Layout.chtmlのヘッダー部</span></p><p data-pasted="true"><!DOCTYPE html></p><p><html lang="en"></p><p><head></p><p> <meta charset="utf-8" /></p><p> <meta name="viewport" content="width=device-width, initial-scale=1.0" /></p><p> <title>@ViewData["Title"] - Kakei</title></p><p> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /></p><p> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /></p><p> <link rel="stylesheet" href="~/Kakei.styles.css" asp-append-version="true" /></p><p> <span style="font-size: 18px;"><strong> <script src="<a data-fr-linked="true" href="https://cdn.jsdelivr.net/npm/chart.js" style="font-size: 18px;">https://cdn.jsdelivr.net/npm/chart.js"&gt</a>;</script></strong></span></p><p></head></p><p><span style="color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;" data-pasted="true">ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー</span></p><p><span style="color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">または、ページ内に追加。</span></p><ul style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pasted="true"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">または、フロントエンドビルドシステムを使用している場合は、npmまたはパッケージマネージャーを介してインストールします。</li></ul><h3 data-bm="59" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; display: inline-block; font: 20px / 22px Roboto, sans-serif; color: rgba(0, 0, 0, 0.8); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pasted="true"><strong style="font-weight: 700;">コントローラーを作成する</strong></h3><ul data-bm="60" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; color: rgba(0, 0, 0, 0.8); font-family: Roboto, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">データ取得を処理するコントローラーを作成し、それをビューに渡します。</li></ul><p data-pasted="true">public class ChartController : Controller</p><p>{</p><p> public IActionResult Index()</p><p> {</p><p> // Example data</p><p> var chartData = new</p><p> {</p><p> Labels = new[] { "January", "February", "March", "April" },</p><p> Data = new[] { 10, 20, 30, 40 }</p><p> };</p><p><br></p><p> return View(chartData);</p><p> }</p><p>}</p><p>ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー</p><div tabindex="0" style="color: rgba(0, 0, 0, 0.8); padding: 20px; flex: 1 1 0%; font-size: 16px; line-height: 26px; font-weight: 400; overflow: auto; max-height: 420px; font-family: Roboto, Helvetica, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;" data-pasted="true"><h3 data-bm="61" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; display: inline-block; font: 20px / 22px Roboto, sans-serif;"><strong style="font-weight: 700;">ビューを作成する</strong></h3><ul data-bm="62" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">グラフの Razor ビュー () を作成します。<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">Index.cshtml</code></li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">グラフをレンダリングするための要素を追加します。<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"><canvas></code></li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">JavaScript を使用して、Chart.js チャートを初期化します。<pre data-priority="2" style="background: none 0% 0% / auto repeat scroll padding-box border-box rgb(245, 245, 245); border-color: rgba(0, 0, 0, 0.1); border-style: solid; border-width: 1px; border-image: none 100% / 1 / 0 stretch; border-radius: 8px; overflow: hidden;"><div data-bm="72" style="display: flex; height: 28px; flex-direction: row; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); background: none 0% 0% / auto repeat scroll padding-box border-box rgb(247, 240, 255);"><h5 style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 0px; padding: revert; font-style: inherit; font-variant: inherit; font-weight: 700; font-stretch: inherit; line-height: 18px; font-family: inherit; font-optical-sizing: inherit; font-size-adjust: inherit; font-kerning: inherit; font-feature-settings: inherit; font-variation-settings: inherit; font-size: 16px; display: inline-block; color: rgb(83, 41, 130);">Html</h5><div style="height: 28px;"><button type="button" tabindex="" title="Copy code" style="box-sizing: border-box; margin: 0px; padding: 0px; font: 400 13px / 20px Roboto, Helvetica, sans-serif; background-color: rgb(223, 211, 237); border-color: rgba(0, 0, 0, 0); border-style: solid; border-width: 1px; border-image: none 100% / 1 / 0 stretch; display: grid; grid-auto-flow: column; align-items: center; gap: 4px; cursor: pointer; color: rgb(83, 41, 130) !important; text-decoration: none !important; border-radius: 9999px; padding-block: 3px; padding-inline: 8px;"><div style="box-sizing: border-box; margin: 0px; padding: 0px; min-inline-size: 0px; white-space: nowrap; overflow: clip; text-overflow: ellipsis; max-block-size: calc(1lh);">Copy code</div></button></div></div><code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255); display: block; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px 16px 16px;">@model dynamic <<span style="color: rgb(34, 134, 58);">div</span>> <<span style="color: rgb(34, 134, 58);">canvas</span> <span style="color: rgb(0, 92, 197);">id</span>=<span style="color: rgb(3, 47, 98);">"myChart"</span>></<span style="color: rgb(34, 134, 58);">canvas</span>> </<span style="color: rgb(34, 134, 58);">div</span>> <<span style="color: rgb(34, 134, 58);">script</span>> <span style="color: rgb(215, 58, 73);">var</span> ctx = <span style="color: rgb(215, 58, 73);">document</span>.<span style="color: rgb(111, 66, 193);">getElementById</span>(<span style="color: rgb(3, 47, 98);">'myChart'</span>).<span style="color: rgb(111, 66, 193);">getContext</span>(<span style="color: rgb(3, 47, 98);">'2d'</span>); <span style="color: rgb(215, 58, 73);">var</span> myChart = <span style="color: rgb(215, 58, 73);">new</span> <span style="color: rgb(111, 66, 193);">Chart</span>(ctx, { <span style="color: rgb(0, 92, 197);">type</span>: <span style="color: rgb(3, 47, 98);">'bar'</span>, <span style="color: rgb(106, 115, 125);">// Chart type (e.g., bar, line, pie)</span> <span style="color: rgb(0, 92, 197);">data</span>: { <span style="color: rgb(0, 92, 197);">labels</span>: @<span style="color: rgb(111, 66, 193);">Html</span>.<span style="color: rgb(111, 66, 193);">Raw</span>(<span style="color: rgb(111, 66, 193);">Json</span>.<span style="color: rgb(111, 66, 193);">Serialize</span>(<span style="color: rgb(111, 66, 193);">Model</span>.Labels)), <span style="color: rgb(106, 115, 125);">// X-axis labels</span> <span style="color: rgb(0, 92, 197);">datasets</span>: [{ <span style="color: rgb(0, 92, 197);">label</span>: <span style="color: rgb(3, 47, 98);">'Sample Data'</span>, <span style="color: rgb(0, 92, 197);">data</span>: @<span style="color: rgb(111, 66, 193);">Html</span>.<span style="color: rgb(111, 66, 193);">Raw</span>(<span style="color: rgb(111, 66, 193);">Json</span>.<span style="color: rgb(111, 66, 193);">Serialize</span>(<span style="color: rgb(111, 66, 193);">Model</span>.Data)), <span style="color: rgb(106, 115, 125);">// Y-axis data</span> <span style="color: rgb(0, 92, 197);">backgroundColor</span>: <span style="color: rgb(3, 47, 98);">'rgba(75, 192, 192, 0.2)'</span>, <span style="color: rgb(0, 92, 197);">borderColor</span>: <span style="color: rgb(3, 47, 98);">'rgba(75, 192, 192, 1)'</span>, <span style="color: rgb(0, 92, 197);">borderWidth</span>: <span style="color: rgb(0, 92, 197);">1</span> }] }, <span style="color: rgb(0, 92, 197);">options</span>: { <span style="color: rgb(0, 92, 197);">scales</span>: { <span style="color: rgb(0, 92, 197);">y</span>: { <span style="color: rgb(0, 92, 197);">beginAtZero</span>: <span style="color: rgb(0, 92, 197);">true</span> } } } }); </<span style="color: rgb(34, 134, 58);">script</span>> </code></pre></li></ul><h3 data-bm="63" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; display: inline-block; font: 20px / 22px Roboto, sans-serif;"><strong style="font-weight: 700;">5. スタイルとカスタマイズ</strong></h3><ul data-bm="64" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">Chart.jsオプション (色、ツールチップ、アニメーションなど) を変更してグラフをカスタマイズします。</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">必要に応じて、レイアウトと応答性のために CSS を追加します。</li></ul><h3 data-bm="65" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; display: inline-block; font: 20px / 22px Roboto, sans-serif;"><strong style="font-weight: 700;">6. テストとデバッグ</strong></h3><ul data-bm="66" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">アプリケーションを実行し、コントローラのアクション(例: )に移動します。<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);">/Chart/Index</code></li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;">グラフが正しくレンダリングされ、データが表示されることを確認します。</li></ul><h3 data-bm="67" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert; display: inline-block; font: 20px / 22px Roboto, sans-serif;"><strong style="font-weight: 700;">7. オプションの機能強化</strong></h3><ul data-bm="68" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: revert; padding: revert;"><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">動的データ</strong>: データベースまたは API からデータをフェッチし、ビューに渡します。</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong style="font-weight: 700;">AJAX 統合</strong>: AJAX を使用して、ページを更新せずにグラフを動的に更新します。</li><li style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin-top: revert; margin-right: revert; margin-bottom: 8px; margin-left: revert; padding: revert;"><strong data-bm="85" style="font-weight: 700;">複数のチャート</strong>: 複数の要素を追加し、複数のChart.jsインスタンスを初期化します。<code style="border-radius: 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(255, 255, 255);"><canvas></code></li></ul><p data-bm="69" style="border: 0px; border-collapse: collapse; border-spacing: 0px; list-style-position: initial; list-style-image: initial; list-style-type: revert; margin: 8px 0px; padding: revert; -webkit-line-clamp: revert;">この概要は、Chart.jsを使用して ASP.NET Core MVC でグラフを作成するための基礎を提供します。アプリケーションの要件に基づいてさらに拡張できます。</p></div><p><br></p>
コピーする
添付画像
画像を変更
Back to List
//検索文:Editor内でHTMLコードをコピーさせる