简体   繁体   中英

WPF Toolkit Charting: how to remove line series data points and still get different line series colors?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM