# .NET and More > WPF, WCF, WF >  Maximum y Achse Chart WPF als Variable

## Goofy

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.

----------


## passel

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.



```
<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.

----------


## kensen

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



```
populationChart.Axes.LinearAxis.Maximum = myMax
```

Or, when Binding is required:



```
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.ComponentModelImplements INotifyPropertyChangedPublic Event PropertyChanged...Public Property myMax - must be a Property, it won't work with a simple variableRaiseEvent PropertyChanged in myMax SetSet the DataContext either by Code or in XAML

Now Binding works



```
<TextBox Width="100" Height="25" Text="{Binding myMax}"/>
```

----------

