1

I have used Jim McCurdy's very helpful answer to this StackOverflow question to avoid drawing data points in a WPF Toolkit chart with multiple line series.

However: if I do not apply Jim's XAML styles, all chart lines obtain different colors (of course at the expense of data points being displayed), but when I apply the "datapoint-less" styles the line color is constant, resulting in all lines in the chart having the same color.

Is it possible to extend the XAML styles so that the line colors is automatically different for each new line series in the chart?

If I interpret the answer to this StackOverflow question correctly, the problem is fairly easily solved programmatically, but if possible I would prefer an XAML based solution.

Community
  • 1
  • 1
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114

1 Answers1

4

For solving this problem in XAML, one way is to create a different DataPoint style for each color that you want to be assigned to a LineSeries. For example, I've simply done this:

<Style x:Key="InvisibleDataPointBlue" TargetType="{x:Type charting:DataPoint}">
    <Setter Property="Background" Value="Blue"/>
    <Setter Property="Template" Value="{x:Null}"/>
</Style>

<Style x:Key="InvisibleDataPointRed" TargetType="{x:Type charting:DataPoint}">
    <Setter Property="Background" Value="Red"/>
    <Setter Property="Template" Value="{x:Null}"/>
</Style>

<Style x:Key="InvisibleDataPointGreen" TargetType="{x:Type charting:DataPoint}">
    <Setter Property="Background" Value="Green"/>
    <Setter Property="Template" Value="{x:Null}"/>
</Style>

There may be a better way to dynamically assign a new color, but if your needs are modest, this will do.

PIntag
  • 932
  • 11
  • 26
  • Dear PIntag, many thanks for your response. I define the different series dynamically in code, so I would still need to explicitly assign a new style to each new line series in the code. Apparently there is an implicit change of color with each new line series if I don't change the style, it would be good to achieve the same functionality when the data point template is null. But anyway, I appreciate you taking the time to provide this alternative solution. – Anders Gustafsson Nov 25 '11 at 21:08
  • You're welcome -- I'm sorry that I don't have a more general solution to this problem that handles implicit color change with each new line series. There must be a way to do this, but I was not able to find the answer when I was looking at this problem a few months ago. The above solution was enough for my application, so I didn't bother to spend more time researching the issue. – PIntag Nov 25 '11 at 21:29