在Silverlight Toolkit的LineChart中显示不同颜色的线条? [英] Showing lines with different colors on a Silverlight Toolkit’s LineChart?

查看:276
本文介绍了在Silverlight Toolkit的LineChart中显示不同颜色的线条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hy,

我有一个图表,它是在运行时创建的,可以是Line,
Bar或Pie类型。

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

基本上我想要的是在图表上有更多的对比度,这意味着我应该使用不同的颜色。

对于条形图,我使用StylePalette属性来设置图表中将使用的颜色,它的工作正常,但对于Line它没有效果。

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;

这在xaml文件中:

<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>

请注意,我在xaml和codebehind端都尝试了Background和Foreground属性。

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?

推荐答案

风格,它覆盖了线条的背景颜色。
解决方案是从代码后面设置所有的样式。

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;

这篇关于在Silverlight Toolkit的LineChart中显示不同颜色的线条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆