This topic describes local data binding of the control using the DataSource and DataBind properties. The code below shows temperature variation for different months of a year.
Add the following markup within the <cc1: C1Sparkline></cc1:C1Sparkline>.
<cc1:C1Sparkline ID="C1Sparkline1" runat="server"> <SeriesList> <cc1:SparklineSeries Bind="Temperature" /> </SeriesList> </cc1:C1Sparkline>
Add the following code to the Page_Load event, to add data to the control.
To write code in 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();
To write code in 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()
When you run the project, Sparklines appear as shown in the image below.