Results 1 to 3 of 3

Thread: Maximum y Achse Chart WPF als Variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2016
    Posts
    4

    Maximum y Achse Chart WPF als Variable

    Hallo zusammen,

    ich habe im Coding eine Variable als Public definiert, der ich einen Wert zuweise - myMax.

    Im WPF habe ich ein Chart, dem ich diesen Wert als Maximalwert für die Y-Achse zuweisen möchte.

    So habe ich es probiert, da tut sich aber nichts. Es erscheinen gar keine Balken.

    <cht:Chart Name="populationChart" Title="Kosten" Foreground="DarkBlue" Background="DarkOrange" Margin="10,10,10.286,454.429" >
    <cht:Chart.Series>
    <cht:ColumnSeries Title="Kosten [€]" Background="DarkBlue" BorderBrush="Black" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" >
    </cht:ColumnSeries>
    </cht:Chart.Series>

    <cht:Chart.Axes>
    <cht:LinearAxis Orientation="Y" Minimum="0" Maximum="{Binding myMax}" />
    </cht:Chart.Axes>


    </cht:Chart>

    Wie kann ich die Variable hier übergeben?

    Danke.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,406

    Re: Maximum y Achse Chart WPF als Variable

    English Speaking forum. Please translate your posts to English.

    Translation:
    Hello, everyone,

    In the coding I have defined a variable as Public, to which I assign a value - myMax.
    In the WPF I have a chart to which I want to assign this value as the maximum value for the Y-axis.
    So I tried it, but nothing happened. No bars appear at all.

    Code:
    <cht:Chart Name="populationChart" Title="Kosten" Foreground="DarkBlue" Background="DarkOrange" Margin="10,10,10.286,454.429" >
    <cht:Chart.Series>
    <cht:ColumnSeries Title="Kosten [€]" Background="DarkBlue" BorderBrush="Black" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True" >
    </cht:ColumnSeries>
    </cht:Chart.Series>
    
    <cht:Chart.Axes>
    <cht:LinearAxis Orientation="Y" Minimum="0" Maximum="{Binding myMax}" />
    </cht:Chart.Axes>
    
    
    </cht:Chart>
    How can I pass the variable here?

    Thanks.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  3. #3
    New Member
    Join Date
    Oct 2020
    Location
    Europe
    Posts
    10

    Re: Maximum y Achse Chart WPF als Variable

    Set the property of the chart from code, without Binding, something like this:

    Code:
    populationChart.Axes.LinearAxis.Maximum = myMax
    Or, when Binding is required:

    Code:
    Imports System.ComponentModel
    Class MainWindow
        Implements INotifyPropertyChanged
    
        Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
    
        Private _myMax As Integer = 123
        Public Property myMax As Integer
            Get
                Return _myMax
            End Get
            Set(value As Integer)
                _myMax = value
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("myMax"))
            End Set
        End Property
    
        Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
            Me.DataContext = Me
            'or set the DataContext for MainWindow in XAML
            'DataContext="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}"    
        End Sub
    
    End Class
    All of the following is required:
    • Imports System.ComponentModel
    • Implements INotifyPropertyChanged
    • Public Event PropertyChanged...
    • Public Property myMax - must be a Property, it won't work with a simple variable
    • RaiseEvent PropertyChanged in myMax Set
    • Set the DataContext either by Code or in XAML


    Now Binding works

    Code:
    <TextBox Width="100" Height="25" Text="{Binding myMax}"/>
    Last edited by kensen; Nov 4th, 2021 at 10:51 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width