Telerik RadCartesianChart BarSeries Style

时间:2017-05-29 18:15:44

标签: c# wpf telerik

我在telerik WPF中有一个Radcartesian的Bar系列图表,每个Bar的值是两个值的百分比,如果此值小于98%,我需要将条形颜色更改为红色,并且需要更改条形颜色如果价值超过97%,绿色,但我看到的所有事情都改变了系列中所有酒吧的颜色,并且没有发生低于我的目标百分比的酒吧,有人可以帮助解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我已经完成了使用StyleSelector到Barseries的工作。

public override Style SelectStyle(object item,
            DependencyObject container)
        {
            if (SetColor)
            {
                Style st = new Style();
                var _item = (item as CategoricalDataPoint);
                st.TargetType = typeof(Border);
                Setter backGroundSetter = new Setter();
                backGroundSetter.Property = Border.BackgroundProperty;

                if (_item.Value < 98)
                {
                    backGroundSetter.Value = Brushes.Red;
                }
                else
                {
                    backGroundSetter.Value = Brushes.Lime;
                }
                st.Setters.Add(backGroundSetter);
                return st;
            }
            else
                return null;
        }

Ande在Barseries参数中设置它

RadChart.Series.Add(new BarSeries()
                {
                    ShowLabels = true,
                    ClipToPlotArea = true,
                    DefaultVisualStyleSelector = editor.selector,
                    ItemsSource = editor.ItemSourceOptions[i],
                    ValueBinding = new PropertyNameDataPointBinding(editor.SeriesItemsNames[i]),
                    CategoryBinding = new PropertyNameDataPointBinding(editor.CategoryNames[i])
                });