1

嗨,

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

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

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

作为折线图,我试过这个:对于我想使用的线条,可以说 2 种颜色。

    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 和代码隐藏方面也尝试了 Background 和 Foreground 属性。

我已根据此链接完成此操作:

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

基本上我想要的是在图表上的线条上有更多的对比度,这意味着我应该在线条上使用不同的颜色。我用这个例子来演示我在这种特殊情况下面临的问题。

有人有这个问题吗? 有人对此有任何解决方案吗?

4

2 回答 2

3

所有这些 Silverlight 图表的记录都很差/随机。

当心StylePalette已在 Silverlight4 中删除,并发布了与其他对象更一致的新机制和图表类型

于 2011-01-22T13:30:32.780 回答
0

问题是我的样式覆盖了线条的背景颜色。解决方案是从后面的代码中设置所有样式。

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;
于 2009-10-07T06:20:04.247 回答