Showing lines with different colors on a Silverlight Toolkit’s LineChart?

余生长醉 提交于 2019-12-06 14:01:28

问题


Hy,

I have a chart,wich is created in runtime,this could be Line, Bar or Pie type.

Basically what i want is to have more contrast on the lines on the chart,this means i should use different colors on the lines.

For Bar chart i use the StylePalette property to set wich colors will used in the chart,and it's working fine,but for Line it has no effect.

As a Line chart i tried this: For the line i want to use lets say 2 colors.

    Style style = new Style(typeof(Control));
     Setter st = new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Red));
     style.Setters.Add(st);
     Style style2 = new Style(typeof(Control));
Setter st2 = new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Green));
                style2.Setters.Add(st2);

                StylePalette palette = new StylePalette();
                palette.Add(style);
                palette.Add(style2);

                m_oChart.StylePalette = palette;

And this in the xaml file:

<chartingToolkit:Chart x:Name="m_oChart" Style="{StaticResource ChartStyleLegendBottom}" d:IsHidden="True">
                    <chartingToolkit:Chart.StylePalette>
                        <visualizationToolkit:StylePalette>
                            <Style TargetType="Control">
                                <Setter Property="Background" Value="Gray"/>
                            </Style>
                            <Style TargetType="Control">
                                <Setter Property="Background" Value="Black"/>
                            </Style>
                        </visualizationToolkit:StylePalette>
                    </chartingToolkit:Chart.StylePalette>
                </chartingToolkit:Chart>

Note that i tried for Background and Foreground propertys too both on the xaml and codebehind side.

I've done this according to this link:

http://forums.silverlight.net/forums/t/58894.aspx

Basically what i want is to have more contrast on the lines on the chart,this means i should use different colors on the lines. I use this example to demonstrate the problem i'm facing in this particular situation.

Does somebody have this problem? Did somebody have any solution for that?


回答1:


All this Silverlight Charting is poorly/randomly documented.

Beware StylePalette has been dropped in Silverlight4 and new mechanism & chart types released which is/are more consistent with other objects




回答2:


The problem was I had a style which was overriding the Background color of the lines. The solution was to set all the styles from code behind.

Style style = new Style(typeof(Control));
style.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(oColors[colors])));
style.Setters.Add(new Setter(Control.HeightProperty, 5));
style.Setters.Add(new Setter(Control.WidthProperty, 5));
series.DataPointStyle = style;


来源:https://stackoverflow.com/questions/1487145/showing-lines-with-different-colors-on-a-silverlight-toolkit-s-linechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!