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?
UPDATE
Some XAML/code for a better idea.
XAML for DynamicSeriesChart head
<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}}">
XAML for Chart Template
<ana:DynamicSeriesChart.Template>
<ControlTemplate TargetType="charting:Chart">
<Border Background="{DynamicResource ContainerElementContentPanelBgBrush}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<datavis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" />
<chartingprimitives:EdgePanel x:Name="ChartArea" Grid.Row="1" Margin="0,15,0,15" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" />
</chartingprimitives:EdgePanel>
<datavis:Legend x:Name="Legend" Style="{TemplateBinding LegendStyle}" Grid.Row="2" HorizontalAlignment="Left">
<datavis:Legend.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</datavis:Legend.ItemsPanel>
</datavis:Legend>
</Grid>
</Border>
</ControlTemplate>
</ana:DynamicSeriesChart.Template>
Sample from Palette
<Style x:Key="ColumnSeries1Style" TargetType="Control">
<Setter Property="Background" Value="#FFFFA500" />
</Style>
<Style x:Key="ColumnSeries1Style2" TargetType="Shape">
<Setter Property="Fill" Value="#FFFFA500" />
<Setter Property="Stroke" Value="#FFFFA500" />
</Style>
...
…
<datavis:ResourceDictionaryCollection x:Key="ChartPalette">
<ResourceDictionary>
<Style x:Key="DataPointStyle" BasedOn="{StaticResource ColumnSeries1Style}" TargetType="Control" />
<Style x:Key="DataShapeStyle" BasedOn="{StaticResource ColumnSeries1Style2}" TargetType="Shape" />
</ResourceDictionary>
...
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.
(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.)
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.
UPDATE
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.
If your line graph is working, but the other ones have cycling colors, you could style the Palette property to check what type of graph is being used. Then you could apply the whole color palette to the line graph, but have the others convert an index (that you would add to wherever your data is coming from) to a color. For details on the conversion process, see this question.