I create my chart by inserting data points like so:
1.Chart.DefaultView.ChartArea.DataSeries.Clear(); 2.var series = new DataSeries { Definition = new SplineAreaSeriesDefinition() }; 3.foreach (var point in dataPoints) series.Add(point); 4.Chart.DefaultView.ChartArea.DataSeries.Add(series);The points themselves are created thusly. I explicitly specify types for your convenience.
1.var dataPoints = /*[...]*/.Select( (x, y) => new DataPoint((int)x, (double)y).ToArray()When I call the add method, I obtain the graph (supplied) "mychartnormal.png". I'm happy with this graph.
When I do the following manipulation of the graph, I obtain a new figure (supplied) "mychartweird.png". The number formatting of the highlighted values shows unnecessary precision.
1.var series = OverviewChart.DefaultView.ChartArea.DataSeries.FirstOrDefault(); 2.if (ColorPicker.SelectedItem != null && series != null) 3. series.Definition.Appearance.Fill = new SolidColorBrush((Color) ColorPicker.SelectedItem); 4.OverviewChart.DefaultView.ChartArea.DataSeries.Clear(); 5.OverviewChart.DefaultView.ChartArea.DataSeries.Add(series);You may wonder at this point why I am not manipulating the Definition.Appearance.Fill property of the series that I pick out on line one directly. Well, the reason being is that I want to the drawing animation to restart, and I didn't find another way in the API do that. As such I am open to two possible solutions.
Firstly there's the obvious rewrite that solves the problem, but I find it in bad taste to have to recreate the series, since I may need to modify other properties separately, and the copying on line 3 can easily become unwieldy.
1.var series = OverviewChart.DefaultView.ChartArea.DataSeries.FirstOrDefault(); 2.if (ColorPicker.SelectedItem == null || series == null) return; 3.var nseries = new DataSeries() {Definition = series.Definition}; 4.nseries.AddRange( series.Select(datapoint => new DataPoint(datapoint.XValue, datapoint.YValue))); 5.nseries.Definition.Appearance.Fill = new SolidColorBrush((Color) ColorPicker.SelectedItem); 6.OverviewChart.DefaultView.ChartArea.DataSeries.Clear(); 7.OverviewChart.DefaultView.ChartArea.DataSeries.Add(nseries);Secondly all I really need is to restart the animation. I only found one relevant post, which said to use Chart.ResetTheme(), which didn't work for me.
<Style x:Key="ccTemplate" TargetType="{x:Type ContentControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContentControl}" > <Grid x:Name="listBoxGrid" TextOptions.TextFormattingMode="Display"> <Grid.RowDefinitions> <RowDefinition Height="200*"/> <RowDefinition Height="60" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid Grid.ColumnSpan="6" > <ContentPresenter /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter></Style><Style x:Key="{x:Type control:ListBoxControl}" TargetType="{x:Type control:ListBoxControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ContentControl Style="{StaticResource ccTemplate}" x:Name="cc"> <telerikNavigation:RadTreeView Name="mainList" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsSource}" ItemTemplate="{DynamicResource MainDataTemplate}" ItemContainerStyle="{DynamicResource MainStyle}" MinWidth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MinWidth}" ScrollViewer.HorizontalScrollBarVisibility="Auto" BorderBrush="#FF00569F" Background="{DynamicResource ListItemBackground}" BorderThickness="1" SelectionMode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectionMode, FallbackValue=Single}" IsDragDropEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDragDropEnabled, FallbackValue=False}" IsDropPreviewLineEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropPreviewLineEnabled, FallbackValue=True}" AllowDrop="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AllowDrop, FallbackValue=True}" > </telerikNavigation:RadTreeView> </ContentControl> </ControlTemplate> </Setter.Value> </Setter></Style><Style x:Key="{x:Type control:ListBoxControl}" TargetType="{x:Type control:ListBoxControl}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsSource}" /> <Setter Property="ItemTemplate" Value="{DynamicResource MainDataTemplate}"/> <Setter Property="ItemContainerStyle" Value="{DynamicResource MainStyle}"/> <Setter Property="BorderBrush" Value="#FF00569F"/> <Setter Property="Background" Value="{DynamicResource ListItemBackground}"/> <Setter Property="IsLineEnabled" Value="True"/> <Setter Property="IsRootLinesEnabled" Value="False"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="IsExpandOnSingleClickEnabled" Value="True" /> <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ValidationTemplate}" /> <Setter Property="SelectionMode" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectionMode, FallbackValue=Single}" /> <Setter Property="IsDragDropEnabled" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDragDropEnabled, FallbackValue=False}" /> <Setter Property="IsDropPreviewLineEnabled" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropPreviewLineEnabled, FallbackValue=True}" /> <Setter Property="AllowDrop" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AllowDrop, FallbackValue=True}" /> </Style><ControlTemplate x:Key="RadTreeViewMainItemControlTemplate" TargetType="{x:Type telerikNavigation:RadTreeViewItem}"> <Grid x:Name="listBoxGrid" TextOptions.TextFormattingMode="Display"> <Grid.RowDefinitions> <RowDefinition Height="200*"/> <RowDefinition Height="60" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition Width="80" /> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid Grid.ColumnSpan="6" > <Grid x:Name="RootElement" MinWidth="300" Cursor="Hand"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition/> </Grid.RowDefinitions> <Grid x:Name="HeaderRow" MinHeight="{TemplateBinding MinHeight}" SnapsToDevicePixels="True" Background="Transparent"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Border Grid.ColumnSpan="6" Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0" /> <Border x:Name="MouseOverVisual" Opacity="0" Grid.ColumnSpan="6" Background="{DynamicResource ListItemMouseOver}" BorderBrush="{DynamicResource ListItemMouseOverBorder}" BorderThickness="0" /> <Border x:Name="SelectionUnfocusedVisual" Visibility="Collapsed" Grid.ColumnSpan="6" BorderBrush="Transparent" Background="{DynamicResource ListItemUnSelect}" BorderThickness="0" /> <Border x:Name="SelectionVisual" Visibility="Collapsed" Grid.ColumnSpan="6" BorderBrush="{DynamicResource ListItemSelectBorder}" Background="{DynamicResource ListItemSelect}" BorderThickness="0" /> <StackPanel x:Name="IndentContainer" Orientation="Horizontal"> <Rectangle x:Name="IndentFirstVerticalLine" /> </StackPanel> <Grid x:Name="ListRootContainer" HorizontalAlignment="Center" MinWidth="20" Grid.Column="1"> <ToggleButton Name="MainToggle" Style="{DynamicResource ExpanderStyle}" IsTabStop="False" IsChecked="{TemplateBinding IsExpanded}"/> <Grid x:Name="LoadingVisual" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed"> <Grid.RenderTransform> <TransformGroup> <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/> </TransformGroup> </Grid.RenderTransform> <Path Stretch="Fill" Stroke="{TemplateBinding Foreground}" StrokeStartLineCap="Round" StrokeThickness="1" Width="10" Height="10" Data="M1,0A1,1,90,1,1,0,-1"/> <Path Fill="{TemplateBinding Foreground}" Stretch="Fill" StrokeThickness="1" HorizontalAlignment="Left" Margin="5,-1.5,0,0" VerticalAlignment="Top" Width="4" Height="4" Data="M0,-1.1L0.1,-1 0,-0.9"/> </Grid> </Grid> <CheckBox x:Name="CheckBoxElement" Margin="5,0,0,0" VerticalAlignment="Center" IsTabStop="False" Visibility="Collapsed" Grid.Column="2"> </CheckBox> <RadioButton x:Name="RadioButtonElement" Margin="5,0,0,0" VerticalAlignment="Center" IsTabStop="False" Visibility="Collapsed" Grid.Column="2"> </RadioButton> <Image x:Name="Image" HorizontalAlignment="Center" Margin="2" MaxHeight="16" MaxWidth="16" VerticalAlignment="Center" Grid.Column="3" Source="{TemplateBinding DefaultImageSrc}"/> <Rectangle x:Name="FocusVisual"/> <Grid Grid.Column="4" Grid.ColumnSpan="2"> <ContentPresenter x:Name="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" ContentSource="Header"/> <ContentPresenter x:Name="EditHeaderElement" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" ContentTemplate="{TemplateBinding HeaderEditTemplate}"/> </Grid> </Grid> <Border BorderThickness="0 0 0 2" BorderBrush="{DynamicResource BottomListItem}" /> <ItemsPresenter x:Name="ItemsHost" Visibility="Collapsed" Grid.Row="1" DataContext="{Binding}" /> <Border BorderThickness="0 0 0 2" BorderBrush="{DynamicResource BottomListItem}" /> </Grid> </Grid> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsInEditMode" Value="True"> <Setter Property="Visibility" TargetName="Header" Value="Collapsed"/> <Setter Property="Visibility" TargetName="EditHeaderElement" Value="Visible"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Visibility" TargetName="SelectionVisual" Value="Visible"/> <Setter Property="BorderThickness" Value="1" /> </Trigger> <Trigger Property="IsFocused" Value="True"> <Setter Property="Visibility" TargetName="FocusVisual" Value="Visible"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="True"/> <Condition Property="IsSelectionActive" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Opacity" TargetName="SelectionVisual" Value="1"/> <Setter Property="Visibility" TargetName="SelectionUnfocusedVisual" Value="Visible"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" TargetName="Header" Value="0.5"/> </Trigger> <Trigger Property="IsExpanded" Value="True"> <Setter Property="Visibility" TargetName="ItemsHost" Value="Visible"/> </Trigger> <Trigger Property="HasItems" Value="False"> <Setter Property="Visibility" TargetName="MainToggle" Value="Collapsed" /> </Trigger> <Trigger Property="IsLoadingOnDemand" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="00:00:01" RepeatBehavior="Forever" Storyboard.TargetName="LoadingVisualAngleTransform" Storyboard.TargetProperty="Angle" From="0" To="359"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Setter Property="Visibility" TargetName="LoadingVisual" Value="Visible"/> </Trigger> <Trigger Property="IsDragOver" Value="True"> <Setter Property="Opacity" TargetName="MouseOverVisual" Value="1"/> </Trigger> <Trigger Property="IsMouseOver" SourceName="HeaderRow" Value="True"> <Setter Property="Opacity" TargetName="MouseOverVisual" Value="1"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate>
