Skip to content

Silverlight Chart Control add series values

November 25, 2012
XAML code
<toolkit:Chart Margin="490,12,12,0" Name="chart1"  
VerticalAlignment="Top" Height="307" LegendTitle="" 
IsTabStop="False">
   <toolkit:ColumnSeries ItemsSource ="{Binding}" 
                  IndependentValueBinding="{Binding MonthName}" 
                  DependentValueBinding="{Binding TicketCount}" 
                  AnimationSequence="FirstToLast" 
                  DataPointStyle="{Binding}">  
   </toolkit:ColumnSeries> 
   <toolkit:ColumnSeries ItemsSource ="{Binding}" 
                     IndependentValueBinding="{inding MonthName}" 
                     DependentValueBinding="{Binding HeadCount}" >
   </toolkit:ColumnSeries>
</toolkit:Chart>

In Code behind file (.xaml.cs)
private void Load_TCHC_ColumnChartData()
{
 chart1.Title = "Ticket Count to Head Count Ratio";            
  ((ColumnSeries)chart1.Series[0]).Title = "Ticket Count";
  ((ColumnSeries)chart1.Series[1]).Title = "Head Count";            

List<TC2HCRatio> cust = new List<TC2HCRatio>();
cust.Add(new TC2HCRatio()
         { MonthName = "Jan'12", TicketCount = 100, HeadCount = 200 }
        );
cust.Add(new TC2HCRatio() 
         { MonthName = "Feb'12", TicketCount = 200, HeadCount = 300 }
        );
cust.Add(new TC2HCRatio() 
         { MonthName = "Mar'12", TicketCount = 110, HeadCount = 500 }
        );
cust.Add(new TC2HCRatio() 
         { MonthName = "Apr'12", TicketCount = 360, HeadCount = 610 }
        );
cust.Add(new TC2HCRatio() 
         { MonthName = "May'12", TicketCount = 230, HeadCount = 400 }
        );
cust.Add(new TC2HCRatio() 
         { MonthName = "Jun'12", TicketCount = 100, HeadCount = 220 }
);
this.DataContext = cust;
}

public class TC2HCRatio
  {
     public string MonthName { get; set; }
     public int TicketCount { get; set; }
     public int HeadCount { get; set; }
  }

——————————————–
2) XAML
<toolkit:Chart HorizontalAlignment=”Left” Margin=”10,10,0,0″
Name=”mcChart” Title=”Tickets ” VerticalAlignment=”Top”
Height=”309″ Width=”474″  >
<toolkit:ColumnSeries
IndependentValueBinding=”{Binding Path=Key}”
DependentValueBinding=”{Binding Path=Value}”
FontFamily=”Comic Sans MS” FontSize=”10″ Title=”Breached”
DataContext=”{Binding}”
Background=”Black” BorderBrush=”#FFAF0000″>
</toolkit:ColumnSeries>
<toolkit:ColumnSeries
IndependentValueBinding=”{Binding Path=Key}”
DependentValueBinding=”{Binding Path=Value}”
FontFamily=”Comic Sans MS” FontSize=”10″ Title=”Total” >
</toolkit:ColumnSeries>
<toolkit:LineSeries
IndependentValueBinding=”{Binding Path=Key}”
DependentValueBinding=”{Binding Path=Value}”
FontFamily=”Comic Sans MS” FontSize=”10″ Title=”SLP %”  >
</toolkit:LineSeries>
</toolkit:Chart>

.XAML.CS
private void LoadColumnChartData()
{
((ColumnSeries)mcChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]
{   new KeyValuePair<string, int>(“CHN”, 12),
new KeyValuePair<string, int>(“GGN”, 25),
new KeyValuePair<string, int>(“HYD”, 5),
new KeyValuePair<string, int>(“MUM”, 6)
};

((ColumnSeries)mcChart.Series[1]).ItemsSource =
new KeyValuePair<string, int>[]
{   new KeyValuePair<string, int>(“CHN”, 14),
new KeyValuePair<string, int>(“GGN”, 27),
new KeyValuePair<string, int>(“HYD”, 7),
new KeyValuePair<string, int>(“MUM”, 8)
};
((LineSeries)mcChart.Series[2]).ItemsSource =
new KeyValuePair<string, double>[]
{
new KeyValuePair<string, double>(“CHN”, 99.9),
new KeyValuePair<string, double>(“GGN”, 79.9),
new KeyValuePair<string, double>(“HYD”, 70.0),
new KeyValuePair<string, double>(“MUM”, 80.0)
};

}

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: