CHart demo
<UserControl x:Class="Silverlighchartdemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid AutoGenerateColumns="False" Height="126" HorizontalAlignment="Left" Margin="37,50,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="290" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="114,19,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
<toolkit:Chart HorizontalAlignment="Left" Margin="96,223,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Top">
<toolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y">
<toolkit:ColumnSeries.ItemsSource>
<PointCollection>
<Point>1,10</Point>
<Point>2,20</Point>
<Point>3,30</Point>
<Point>4,40</Point>
</PointCollection>
</toolkit:ColumnSeries.ItemsSource>
</toolkit:ColumnSeries>
</toolkit:Chart>
</Grid>
</UserControl>
<UserControl x:Class="Silverlighchartdemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid AutoGenerateColumns="False" Height="126" HorizontalAlignment="Left" Margin="37,50,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="290" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="114,19,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
<toolkit:Chart HorizontalAlignment="Left" Margin="96,223,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Top">
<toolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y">
<toolkit:ColumnSeries.ItemsSource>
<PointCollection>
<Point>1,10</Point>
<Point>2,20</Point>
<Point>3,30</Point>
<Point>4,40</Point>
</PointCollection>
</toolkit:ColumnSeries.ItemsSource>
</toolkit:ColumnSeries>
</toolkit:Chart>
</Grid>
</UserControl>
.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SharePoint.Client;
using System.Windows.Controls.DataVisualization.Charting;
namespace Silverlighchartdemo
{
public partial class MainPage : UserControl
{
public string webFullURL = @"URL";
List stud = null;
ListItemCollection lists = null;
List<Student> students = new List<Student>();
private delegate void UpdateUIMethod(List<Student> studentList);
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ClientContext spContext = ClientContext.Current;
if (spContext == null)
{
spContext = new ClientContext(webFullURL);
spContext.Load(spContext.Web);
stud = spContext.Web.Lists.GetByTitle("StudentInfo");
spContext.Load(stud);
CamlQuery query = new CamlQuery();
string strQuery = @"<View><ViewFields><FieldRef Name='AssignedTo'/>
<FieldRef Name='Name'/><FieldRef Name='Mathematics'/>
<FieldRef Name='Physics'/><FieldRef Name='Chemistry'/>
<FieldRef Name='Computer'/></ViewFields></View>";
query.ViewXml = strQuery;
lists = stud.GetItems(query);
spContext.Load(lists);
spContext.ExecuteQueryAsync(OnSiteLoadSuccess, null);
}
}
private void OnSiteLoadSuccess(object sender, ClientRequestSucceededEventArgs e)
{
foreach (ListItem item in lists)
{
Student student = new Student();
student.Name = item["Name"].ToString();
student.Mathematics = Int32.Parse(item["Mathematics"].ToString());
student.Physics = Int32.Parse(item["Physics"].ToString());
student.Chemistry = Int32.Parse(item["Chemistry"].ToString());
student.Computer = Int32.Parse(item["Computer"].ToString());
students.Add(student);
}
UpdateUIMethod up = new UpdateUIMethod(updateUI);
this.Dispatcher.BeginInvoke(up, students);
}
private void updateUI(List<Student> tasks)
{
dataGrid1.ItemsSource = tasks;
dataGrid1.SelectionMode = DataGridSelectionMode.Single;
}
public class Student
{
public string Name { get; set; }
public int Mathematics { get; set; }
public int Physics { get; set; }
public int Chemistry { get; set; }
public int Computer { get; set; }
}
}
}
No comments:
Post a Comment