Bohrend
Bohrend

Reputation: 1497

setting title property for chart in codebehind not working?

I am trying to set a linearAxis Title property in codebehind, but it is not showing, can someone maybe tell me if I am doing something wrong?

  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Background="White">
        <chart:Chart x:Name="BarChart"  Foreground="Gray" Title="Midwest City Populations">
            <chart:BarSeries
                Title="Population" IndependentValueBinding="{Binding Name}"
                DependentValueBinding="{Binding Population}"
                >
                <chart:BarSeries.DataPointStyle>
                    <Style TargetType="chart:BarDataPoint" x:Name="stylename">
                        <Setter Property="Background" Value="Purple" x:Name="test" />
                    </Style>
                </chart:BarSeries.DataPointStyle>
            </chart:BarSeries>
            <chart:Chart.Axes>
                <chart:CategoryAxis Title="City" Orientation="Y" FontStyle="Italic"/>
                <chart:LinearAxis x:Name="axis_for_bargraph" 
                                  Orientation="X" 
                                  Minimum="10"
                                  Maximum="500"
                                  Title="kaas"
                                  ShowGridLines="True"  FontStyle="Italic"/>
            </chart:Chart.Axes>
        </chart:Chart>

      axis_for_bargraph = new LinearAxis();

        axis_for_bargraph.Title = "MB USed";

Upvotes: 0

Views: 288

Answers (1)

Florian Gl
Florian Gl

Reputation: 6014

Through axis_for_bargraph = new LinearAxis(); you're creating a new inctance and give it the Title, not the instance displayed in the UI.

If this results in an accessviolation, you need to access it on another way. Maybe this will work:

Axis axis = BarChart.Axes.FindOrDefault(a => a.Name == "axis_for_bargraph");
if (axis != null)
    axis.Title = "MB Used";

But I think it's way easier to solve this problem with binding. Just bind a property, f.e. LinearAxisTitle, to the title of your LinearAxis and change this property.

Upvotes: 1

Related Questions