locked
einfaches Chart in SL4? RRS feed

  • Frage

  • Hallo,

    Ich suche eine einfache Möglichkeit ein kleines Chart in SL4 zu benutzen.

    Hat jemand einen Tipp?

     

    Gruss jens

    Dienstag, 1. Juni 2010 10:54

Antworten

  • Hallo Jens,
    Ich suche eine einfache Möglichkeit ein kleines Chart in SL4 zu benutzen.

    Hat jemand einen Tipp?

    siehe http://silverlight.codeplex.com/ . Das Silverlight Toolkit beinhaltet auch ein Chart Control.

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    Dienstag, 1. Juni 2010 12:51
  • Hi Jens,
    nimm das Chart aus dem SL4-ToolKit. Hier mal eine Demo:
     
    Der XAML-Code:
    <navigation:Page 
    xmlns:ctk="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    x:Class="SilverlightApplication1.Page03" 
    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"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    d:DesignWidth="640" d:DesignHeight="480"
    Title="Page3 Page"
    xmlns:my="clr-namespace:SilverlightApplication1">
     <navigation:Page.Resources>
      <my:Page03ViewModel x:Key="VM" />
     </navigation:Page.Resources>
     <Grid x:Name="LayoutRoot">
      <ctk:Chart Name="MainChart" Height="500">
       <ctk:Chart.Series>
        <ctk:ColumnSeries ItemsSource="{Binding Source={StaticResource VM}, Path=Data}"
                 DependentValueBinding="{Binding Value}" 
                 IndependentValueBinding="{Binding Key}"
                 >
         <ctk:ColumnSeries.DependentRangeAxis>
          <ctk:LinearAxis Orientation="Y" Minimum="0" Maximum="100" />
         </ctk:ColumnSeries.DependentRangeAxis>
        </ctk:ColumnSeries>
       </ctk:Chart.Series>
      </ctk:Chart>
     </Grid>
    </navigation:Page>
    

     

    Der ViewModel dazu:

     

    Imports System.Collections.ObjectModel
    Imports System.ComponentModel
    Public Class Page03ViewModel
     Implements INotifyPropertyChanged
     Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
     Private WithEvents aTimer As New DispatcherTimer
     Public Sub New()
      Me._data = New List(Of DataClass)
      For i = 1 To 24
       Me._data.Add(New DataClass With {.Key = 2 * i, .Value = i})
      Next
      With aTimer
       .Interval = TimeSpan.FromMilliseconds(4000)
       .Start()
      End With
     End Sub
     Private Sub aTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) _
       Handles aTimer.Tick
      Dim aRandom As New Random()
      For i = 0 To 23
       Me._data(i).Value = aRandom.Next(0, 30)
      Next
      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Data"))
     End Sub
     Private _data As List(Of DataClass)
     Public ReadOnly Property Data() As List(Of DataClass)
      Get
       Return New List(Of DataClass)(Me._data)
      End Get
     End Property
    End Class
    Public Class DataClass
     Private _key As Integer
     Public Property Key() As Integer
      Get
       Return _key
      End Get
      Set(ByVal value As Integer)
       _key = value
      End Set
     End Property
     Private _value As Integer
     Public Property Value() As Integer
      Get
       Return _value
      End Get
      Set(ByVal value As Integer)
       _value = value
      End Set
     End Property
    End Class
    

    --
    Viele Gruesse
     
    Peter
     
     
     
     

    --
    Viele Gruesse
     
    Peter
    Dienstag, 1. Juni 2010 13:38

Alle Antworten

  • Hallo Jens,
    Ich suche eine einfache Möglichkeit ein kleines Chart in SL4 zu benutzen.

    Hat jemand einen Tipp?

    siehe http://silverlight.codeplex.com/ . Das Silverlight Toolkit beinhaltet auch ein Chart Control.

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    Dienstag, 1. Juni 2010 12:51
  • Hi Jens,
    nimm das Chart aus dem SL4-ToolKit. Hier mal eine Demo:
     
    Der XAML-Code:
    <navigation:Page 
    xmlns:ctk="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    x:Class="SilverlightApplication1.Page03" 
    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"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    d:DesignWidth="640" d:DesignHeight="480"
    Title="Page3 Page"
    xmlns:my="clr-namespace:SilverlightApplication1">
     <navigation:Page.Resources>
      <my:Page03ViewModel x:Key="VM" />
     </navigation:Page.Resources>
     <Grid x:Name="LayoutRoot">
      <ctk:Chart Name="MainChart" Height="500">
       <ctk:Chart.Series>
        <ctk:ColumnSeries ItemsSource="{Binding Source={StaticResource VM}, Path=Data}"
                 DependentValueBinding="{Binding Value}" 
                 IndependentValueBinding="{Binding Key}"
                 >
         <ctk:ColumnSeries.DependentRangeAxis>
          <ctk:LinearAxis Orientation="Y" Minimum="0" Maximum="100" />
         </ctk:ColumnSeries.DependentRangeAxis>
        </ctk:ColumnSeries>
       </ctk:Chart.Series>
      </ctk:Chart>
     </Grid>
    </navigation:Page>
    

     

    Der ViewModel dazu:

     

    Imports System.Collections.ObjectModel
    Imports System.ComponentModel
    Public Class Page03ViewModel
     Implements INotifyPropertyChanged
     Public Event PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
     Private WithEvents aTimer As New DispatcherTimer
     Public Sub New()
      Me._data = New List(Of DataClass)
      For i = 1 To 24
       Me._data.Add(New DataClass With {.Key = 2 * i, .Value = i})
      Next
      With aTimer
       .Interval = TimeSpan.FromMilliseconds(4000)
       .Start()
      End With
     End Sub
     Private Sub aTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) _
       Handles aTimer.Tick
      Dim aRandom As New Random()
      For i = 0 To 23
       Me._data(i).Value = aRandom.Next(0, 30)
      Next
      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Data"))
     End Sub
     Private _data As List(Of DataClass)
     Public ReadOnly Property Data() As List(Of DataClass)
      Get
       Return New List(Of DataClass)(Me._data)
      End Get
     End Property
    End Class
    Public Class DataClass
     Private _key As Integer
     Public Property Key() As Integer
      Get
       Return _key
      End Get
      Set(ByVal value As Integer)
       _key = value
      End Set
     End Property
     Private _value As Integer
     Public Property Value() As Integer
      Get
       Return _value
      End Get
      Set(ByVal value As Integer)
       _value = value
      End Set
     End Property
    End Class
    

    --
    Viele Gruesse
     
    Peter
     
     
     
     

    --
    Viele Gruesse
     
    Peter
    Dienstag, 1. Juni 2010 13:38
  • Danke, habs installiert.

    Leider bekomme ich kein Chart zum laufen, weil es leider nirgendwo eine Einführung zum Thema gibt. Hab vieleicht jemand ein kleines C&P-Beispiel in C#?

     

    Gruss Jens

    Mittwoch, 2. Juni 2010 22:06
  • Hallo Jens,

    Leider bekomme ich kein Chart zum laufen, weil es leider nirgendwo eine Einführung zum Thema gibt. Hab vieleicht jemand ein kleines C&P-Beispiel in C#?

    Öhm. Unterhalb von jedem Beispiel in der bereits verlinkten Tookit Demo sind die Verweise auf die Sourcen eingeblendet.

    Peters Beispiel ist auch vorhanden.

    Was also fehlt noch?

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    Mittwoch, 2. Juni 2010 23:28
  • Die Beispiele sind z.b. alle mit Binding, das ich noch nicht so gut kenne und damit nicht genau verstehe. Ich 

    habe z.b. mal ein line-series-chart auf meine XAML gezogen und erhalte:

     

    <toolkit:LineSeries   Name="lineSeries1"  />

    Wie kann ich da jetzt in c# X und Y-Werte eintragen?

     

    Gruss jens

    Sonntag, 6. Juni 2010 20:53
  • Hallo jens Brenner,

    Bitte schau Dir mal an folgender Artikel von Tim Heuer wo gezeigt wird wie man mit den Charts arbeitet.

    Insbesondere kann man sehen wie interessant kann man durch Code die Charts mit bestimmte Werte einbinden (Klasse SalesData im Beispiel – siehe auch Public Class DataClass in Peters obigem Beispiel)

    Und dann schau Dir mal an die Zeile:

    salesData[2].ChartSaleCount = Convert.ToInt32(e.NewValue); (Y Wert wird durch C# Code geändert)

    Grüße,

    Robert

    Mittwoch, 9. Juni 2010 11:09