title: Stopping WPF Chart Colors From Cycling on Refresh/Update
body: <p>I have a chart that is pulling data constantly, and the refresh rate is set to 2 minutes at the moment. The problem is that each time the chart updates, the colors change to be whatever is next in the cycle. I thought that perhaps I could have the chart completely reset on refresh, to always start the palette colors at 0 or 1 each time, but so far no luck. Any ideas? </p>
  
  <p>UPDATE</p>
  
  <p>Some XAML/code for a better idea.</p>
  
  <p>XAML for DynamicSeriesChart head</p>
  
  <pre><code>    &lt;ana:DynamicSeriesChart SeriesSource="{Binding ChartSeries}" Title="{Binding ChartTitle}" Palette="{StaticResource ChartPalette}" Grid.Row="1" LegendTitle="Legend" Margin="0,25,0,0" Visibility="{Binding ShowGraph, Converter={StaticResource BoolToVisConv}}"&gt;
  </code></pre>
  
  <p>XAML for Chart Template</p>
  
  <pre><code>        &lt;ana:DynamicSeriesChart.Template&gt;
              &lt;ControlTemplate TargetType="charting:Chart"&gt;
                  &lt;Border Background="{DynamicResource ContainerElementContentPanelBgBrush}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"&gt;
                      &lt;Grid&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="Auto" /&gt;
                              &lt;RowDefinition Height="*" /&gt;
                              &lt;RowDefinition Height="Auto" /&gt;
                          &lt;/Grid.RowDefinitions&gt;
  
                          &lt;datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" /&gt;
  
                          &lt;chartingprimitives:EdgePanel x:Name="ChartArea" Grid.Row="1" Margin="0,15,0,15" Style="{TemplateBinding ChartAreaStyle}"&gt;
                              &lt;Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" /&gt;
                              &lt;Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" /&gt;
                          &lt;/chartingprimitives:EdgePanel&gt;
  
                          &lt;datavis:Legend x:Name="Legend" Style="{TemplateBinding LegendStyle}" Grid.Row="2" HorizontalAlignment="Left"&gt;
                              &lt;datavis:Legend.ItemsPanel&gt;
                                  &lt;ItemsPanelTemplate&gt;
                                      &lt;WrapPanel Orientation="Horizontal"/&gt;
                                  &lt;/ItemsPanelTemplate&gt;
                              &lt;/datavis:Legend.ItemsPanel&gt;
                          &lt;/datavis:Legend&gt;
                      &lt;/Grid&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/ana:DynamicSeriesChart.Template&gt;
  </code></pre>
  
  <p>Sample from Palette</p>
  
  <pre><code>&lt;Style x:Key="ColumnSeries1Style" TargetType="Control"&gt;
      &lt;Setter Property="Background" Value="#FFFFA500" /&gt;
  &lt;/Style&gt;
  &lt;Style x:Key="ColumnSeries1Style2" TargetType="Shape"&gt;
      &lt;Setter Property="Fill" Value="#FFFFA500" /&gt;
      &lt;Setter Property="Stroke" Value="#FFFFA500" /&gt;
  &lt;/Style&gt;
  ...
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;datavis:ResourceDictionaryCollection x:Key="ChartPalette"&gt;
      &lt;ResourceDictionary&gt;
          &lt;Style x:Key="DataPointStyle" BasedOn="{StaticResource ColumnSeries1Style}" TargetType="Control" /&gt;
          &lt;Style x:Key="DataShapeStyle" BasedOn="{StaticResource ColumnSeries1Style2}" TargetType="Shape" /&gt;
      &lt;/ResourceDictionary&gt;
  ...
  </code></pre>
  
  <p>The reload calls Refresh(), which is a long query that sets new Params. That goes to LoadData(), which goes to ApplyResults(), which clears the ChartSeries and then applies the new values. </p>
  
  <p><em>(I'm hesitant to put up code-behind or cs as none of it is mine (and still somewhat confusing to me, references and references everywhere). I'm still relatively new at being involved with it in this project, and still discovering new parts as I try to solve this. If specifics or operation flow is needed I'll do my best to hunt down those parts.)</em></p>
  
  <p>And upon refreshing, the chart (which can be either Area, Bar, Column, or Line) will cycle through the palette colors. For example, lets say 3 bars, currently red/blue/orange. Upon the refresh to update the chart with new data, the colors will change and cycle to whatever is next in the palette - lets say purple/yellow/green. And it will continue cycling throughout the palette (and therefor changing the chart and its legend) for each refresh of data. This happens even without the custom palette.</p>
  
  <p>UPDATE</p>
  
  <p>Looking closer at the issues, the "Line" graph does not have the same behavior as the others. So it is only Column/Bar/Area charts that have this problem. </p>