1

我正在构建一个 Windows 商店应用程序并尝试在 XAML RT Toolkit 中使用图表组件。现在的问题是我想用特定的颜色来表示每个列栏。但后来我没有找到一种方法来做到这一点。对于饼图调色板有一个类似的问题。但这似乎不适用于柱形图中。有人可以帮忙吗?

4

1 回答 1

1

嗨 Rajkumar,我们也有类似的问题。终于成功了。请检查以下链接。

http://blogs.msdn.com/b/delay/archive/2009/02/04/columns-of-a-different-color-customizing-the-appearance-of-silverlight-charts-with-re-template-和-mvvm.aspx

赋予不同的色彩,本质如下。

步骤1。

在 Page.Resource 下创建样式,如下所示。

<Page.Resources>
        <Style
    x:Key="**ColorByPreferenceColumn**"
    TargetType="charting:ColumnDataPoint">
            <Setter Property="Background" Value="DarkGray"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate
                TargetType="charting:ColumnDataPoint">
                        <Border
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid Background="{Binding **ColorBackGround**}">
                                <Rectangle>
                                    <Rectangle.Fill>
                                        <LinearGradientBrush>
                                            <GradientStop Color="#77ffffff" Offset="0"/>
                                            <GradientStop Color="#00ffffff" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Border BorderBrush="#ccffffff" BorderThickness="1">
                                    <Border BorderBrush="#77ffffff" BorderThickness="1"/>
                                </Border>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

第2步。

将样式应用于图表控件。

<charting:Chart  x:Name="BuildStatusChart" Title="Build Status" Foreground="Black" Margin="20,20,20,20">
           <charting:Chart.Series>

                <Series:ColumnSeries Title="Build Status" ItemsSource="{Binding Items}" 
                        IndependentValueBinding="{Binding Index}" HorizontalContentAlignment="Center"
                        DependentValueBinding="{Binding BuildTime}"
                        IsSelectionEnabled="False" SelectionChanged="OnSelectionChanged"  DataPointStyle="{StaticResource ColorByPreferenceColumn}" >
                 </Series:ColumnSeries>
            </charting:Chart.Series>
        </charting:Chart>

第 3 步:

Note : the style name is "ColorByPreferenceColumn"  and color for each bar will be represented by "ColorBackGround". Search the above code segment , to know how it is applied. FInal thing is on code side have class with "ColorBackGround" peoperty.

public class Build : BindableBase
    {
        //Build Class 

 public Build() {}

 private SolidColorBrush _colorBackGround;
        public SolidColorBrush ColorBackGround
        {
            get { return _colorBackGround; }
            set { _colorBackGround = value; }
        }

       // And your properties......
}

第 5 步:

如你所知,当然,

设置绑定集合。在我们的例子中是

((ColumnSeries)this.BuildStatusChart.Series[0]).ItemsSource = items; // items collection of individual objects.

最好的问候, Anish.AR

于 2013-08-02T09:09:14.727 回答