Disable Auto Scale Adjustment on Area Series Chart?

Feb 21, 2013 at 4:11 PM
Hi,

i'm using an Area Series Chart as some kind of Live Monitor by adding/removing Values to/from an ObservableCollection (there are only shown 10 values at once).

This works pretty fine but the problem is, that the Area Series auto adjusts the vertical scale and the grid lines in the Background to the actual minimum and maximum values within the collection. This is kind of annoying.

Is there any way to disable this auto adjustment and set it to a fixed range (e.g. from 0 to 250)?

I tried to set the DependentRangeAxis to new LinearAxis with a min and max value but then i always get an exception.

Does someone know how this works?

Best Regards

Kornelis
Coordinator
Feb 24, 2013 at 8:27 AM
I played a bit with this, but hit an issue someone reported before with missing resources. Now it seems to be a resource that defines an error string to show when something else breaks, so I might have done something wrong, but this is what I tried:
<charting:Chart
    x:Name="LineChartWithAxes"
    Title="Line Chart"
    Margin="70,0">
    <charting:ScatterSeries
        Title="Population"
        IndependentValueBinding="{Binding Name}"
        DependentValueBinding="{Binding Value}"
        IsSelectionEnabled="True">
        <charting:ScatterSeries.DependentRangeAxis>
            <charting:LinearAxis
                Minimum="0"
                Maximum="100"/>
        </charting:ScatterSeries.DependentRangeAxis>
    </charting:ScatterSeries>
</charting:Chart>
The problem seems to be that Minimum and Maximum are nullable types and can't be set through XAML in WinRT/XAML, so you'd need to use a converter, attached property or code behind to set these, but I think it could get you what you need.
Feb 24, 2013 at 9:28 PM
Edited Feb 24, 2013 at 9:29 PM
Hi,

thanks for your help.

I ended up setting it via code behind for a LineSeries like:
((LineSeries)this.LineChart2.Series[0]).DependentRangeAxis = new LinearAxis() { Minimum = 0, Maximum = 100, Orientation = AxisOrientation.Y};
Important is to set the Orientation. Otherwise an exception will occour.
Coordinator
Feb 24, 2013 at 9:40 PM
That's what I was thinking too. I'm glad I could help.
Oct 8, 2014 at 12:57 PM
I tried setting in code behind, but ended with the axis drawn incorrectly.

First my xaml:
    <Grid x:Name="LayoutRoot" Background="Black">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="20" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock TextAlignment="Right" Grid.Column="0" Grid.Row="0" x:Name="leftHeader" Margin="0,0,0,10">Altitude<LineBreak />m</TextBlock>
        <TextBlock TextAlignment="Center" VerticalAlignment="Bottom" Grid.Column="1" Grid.Row="0" x:Name="Title" Margin="20,0,20,0">
            Title</TextBlock>

        <chart:LinearAxis VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="1" x:Name="yAxis"   
                          Orientation="Y" Location="Left" ShowGridLines="True" IsHitTestVisible="False">
        </chart:LinearAxis>
        <Border Grid.Row="1" Grid.Column="1" BorderBrush="White" BorderThickness="2" >
            <Canvas x:Name="drawingCanvas" Grid.Row="1" Grid.Column="1"  >
            </Canvas>
        </Border>
        <chart:LinearAxis HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="1" x:Name="xAxis" 
                      Orientation="X" Location="Bottom" IsHitTestVisible="False">
        </chart:LinearAxis>
    </Grid>
Then in OnLoaded I do this:
        void SimplerChart_Loaded(object sender, RoutedEventArgs e)
        {
            yAxis.Interval = 5.0;
            yAxis.Maximum = 8.0;
            yAxis.Minimum = -18;
            yAxis.ShowGridLines = true;
            yAxis.Title = "m/s²";

            xAxis.Interval = 1.0;
            xAxis.Maximum = 3.0;
            xAxis.Minimum = 0;
            xAxis.ShowGridLines = true;
            xAxis.Title = "sec";
Image

Any idea why it's compressed the x-axis?