2012-01-24 3 views
2

내가 사용하고 WPF 차트 컨트롤이 여기에 http://wpf.codeplex.com/releases/view/40535wpf에서 barchart를 플롯하기 위해 임의의 값을 생성하는 방법은 무엇입니까?

나는 막대 그래프를 그릴려고에서 다운로드이 내 샘플 코드입니다

public partial class Window1 : Window 
{ 
    List<Institute> list = new List<Institute> { 
     new Institute { Subject = "Computers", students = 122 }, 
     new Institute { Subject = "Physics", students = 170 }, 
     new Institute { Subject = "Maths", students = 210 }, 
     new Institute { Subject = "Chemistry", students = 1840 }, 
     new Institute { Subject = "Electronics", students = 140 }, 
     new Institute { Subject = "Economics", students = 20 }, 
     new Institute { Subject = "Science", students = 100 }, 
     new Institute { Subject = "Scocial", students = 110 }, 
     new Institute { Subject = "English", students = 120 }, 
     new Institute { Subject = "Biology", students = 130 }, 
     new Institute { Subject = "Zoology", students = 140 }, 
     new Institute { Subject = "Hindi", students = 150 }}; 

    public Window1() 
    { 
     InitializeComponent(); 
     ColumnSeries bs = mcChart.Series[0] as ColumnSeries; 
     bs.ItemsSource = list;   
    } 

} 
public class Institute 
{ 
    public string Subject 
    { 
     get; 
     set; 
    } 
    public int students 
    { 
     get; 
     set; 
    } 
} 

XAML 코드는

<Window x:Class="net.Window1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
Title="Window1" Height="800" Width="800" xmlns:my="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"> 
<Grid> 
    <DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" 
     Width="800" Height="450" FontSize="12" 
     Background="DarkGray" Foreground="DarkRed"> 
     <DVC:Chart.Series> 
      <DVC:ColumnSeries x:Name="Barchart" Title="Students of an institute" 
     ItemsSource="{Binding}" 
     IndependentValueBinding="{Binding Path=Subject}" 
     DependentValueBinding="{Binding Path=students}" > 
       <DVC:ColumnSeries.DataPointStyle> 
        <Style TargetType="DVC:ColumnDataPoint"> 
         <Setter Property="Background" Value="#001100"/>       
        </Style> 
       </DVC:ColumnSeries.DataPointStyle> 
      </DVC:ColumnSeries>    
     </DVC:Chart.Series> 
    </DVC:Chart> 
</Grid> 

입니다

이 코드를 사용하면 차트를 플로팅 할 수 있지만 동적으로 플로팅해야합니다.

언제든지이 코드를 실행하면서 각 주제마다 지속적으로 임의의 수의 학생을 생성해야하며 그래프는 새로운 값을 기반으로 플롯되어야합니다. 즉, 그래픽에서 GUI의 동적 변경 사항을보고 싶습니다.

가능합니까?

가능한 경우 답변 해주세요.

미리 감사드립니다.

답변

0

여기에 ObservableCollection을 사용할 수 있습니다. 컬렉션이 수정되면 이벤트 CollectionChanged을 발생시키고 차트가 리 바인드됩니다. MSDN의 this 예 또는 this을 확인하십시오.

희망이 당신을 위해 작동합니다.

관련 문제