4

I'd like to override the DataPointStyle of the LineSeries in my WPF Toolkit Chart:

<chart:LineSeries>
    <chart:DataPointSeries.DataPointStyle>
        <Style
            BasedOn="{StaticResource {x:Type chart:LineDataPoint}}"
            TargetType="{x:Type chart:LineDataPoint}">
            <Setter Property="Width" Value="20" />
            <Setter Property="Height" Value="20" />
        </Style>
    </chart:DataPointSeries.DataPointStyle>
</chart:LineSeries>

However when I do this I lose the automatic palette coloring where each series has a different color. Applying a DataPointStyle causes them all to turn orange.

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

3 Answers3

4

Until someone suggests a better method, I've manually set the colors. I guess I won't be using the automatic palette for now.

<Style
    x:Key="SimpleDataPointStyle"
    BasedOn="{StaticResource {x:Type charting:LineDataPoint}}"
    TargetType="{x:Type charting:LineDataPoint}">
    <Setter Property="Width" Value="20" />
    <Setter Property="Height" Value="20" />
</Style>

...

<chart:LineSeries ... >
    <chart:DataPointSeries.DataPointStyle>
        <Style
            BasedOn="{StaticResource SimpleDataPointStyle}"
            TargetType="{x:Type charting:LineDataPoint}">
            <Setter Property="Background" Value="Green" />
        </Style>
    </chart:DataPointSeries.DataPointStyle>
</chart:LineSeries>
<chart:LineSeries ... >
    <chart:DataPointSeries.DataPointStyle>
        <Style
            BasedOn="{StaticResource SimpleDataPointStyle}"
            TargetType="{x:Type charting:LineDataPoint}">
            <Setter Property="Background" Value="Red" />
        </Style>
    </chart:DataPointSeries.DataPointStyle>
</chart:LineSeries>
sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
2

For those interested this can also be done in the code behind that adds a new LineSeries as follows:

ResourceDictionary rd = MyChart.Palette[MyChart.Series.Count % MyChart.Palette.Count];
Style style = new Style(typeof(LineDataPoint), rd["DataPointStyle"] as Style);
style.Setters.Add(new Setter(OpacityProperty, 0.0));

LineSeries ls = new LineSeries()
{
    DataPointStyle = style
};
MyChart.Series.Add(ls);
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
tdc
  • 8,219
  • 11
  • 41
  • 63
  • 2
    if you want to get the Color of each background serie : ResourceDictionary rd = mcLineChart.Palette[mcLineChart.Series.Count % mcLineChart.Palette.Count]; var myBrush = rd["Background"] as Brush; ... SetStyleProperty(sty, Control.BackgroundProperty, myBrush); – Titwan Feb 26 '15 at 03:41
-2

instead of <Setter Property="Background" Value="Green" /> just bind the value to color as a property of the model. So <Setter Property="Background" Value="{Binding Path=Color}" />

abc
  • 1
  • 1