このトピックでは、DataSource プロパティと DataBind プロパティを使用したコントロールのローカルデータ連結について説明します。次のコードは、ある年の月ごとの温度変化を示します。
<cc1: C1Sparkline></cc1:C1Sparkline> 内に次のマークアップを追加します。
<cc1:C1Sparkline ID="C1Sparkline1" runat="server"> <SeriesList> <cc1:SparklineSeries Bind="Temperature" /> </SeriesList> </cc1:C1Sparkline>
次のコードを Page_Load イベントに追加して、データをコントロールに追加します。
C# でコードを書く場合
object[] data = { new { Name = "Januray", Temperature = 10 }, new { Name = "February",Temperature = 17 }, new { Name = "March", Temperature = 25 }, new { Name = "April", Temperature = 37 }, new { Name = "May", Temperature = 39 }, new { Name = "June", Temperature = 43 }, new { Name = "July", Temperature = 34 }, new { Name = "August", Temperature = 36 }, new { Name = "September", Temperature = 30 }, new { Name = "October", Temperature = 27 }, new { Name = "November",Temperature = 20 }, new { Name = "December", Temperature = 15 } }; C1Sparkline1.DataSource = data; C1Sparkline1.DataBind();
VB でコードを書く場合
Dim data As Object() = { New With {Key .Name = "Januray", Key .Temperature = 10}, New With {Key .Name = "February", Key .Temperature = 17}, New With {Key .Name = "March", Key .Temperature = 25}, New With {Key .Name = "April", Key .Temperature = 37}, New With {Key .Name = "May", Key .Temperature = 39}, New With {Key .Name = "June", Key .Temperature = 43}, New With {Key .Name = "July", Key .Temperature = 34}, New With {Key .Name = "August", Key .Temperature = 36}, New With {Key .Name = "September", Key .Temperature = 30}, New With {Key .Name = "October", Key .Temperature = 27}, New With {Key .Name = "November", Key .Temperature = 20}, New With {Key .Name = "December", Key .Temperature = 15} } C1Sparkline1.DataSource = data C1Sparkline1.DataBind()
プロジェクトを実行すると、スパークラインが次の図のように表示されます。