Telerik是一个强大的WPF第三方控件库,这里给出的相关设置代码事例适用于早期版本的Telerik,仅做为一某些情况下的参考。直接复制可能因为版本的问题报错。
1、前台资源:
<Window.Resources>
<Style x:Key="CustomGridLineStyle"
TargetType="Line">
<Setter Property="StrokeDashArray"
Value="1,1" />
</Style>
</Window.Resources>
2、后台代码(自定义直线):
CustomLine customLine = new CustomLine();
customLine.Slope = 2.66;//斜率为0(默认),与X轴平行,为Infinity,与Y轴平行
customLine.YIntercept = 33;//与Y轴的交点
customLine.ElementStyle = (Style)this.FindResource("CustomGridLineStyle");
customLine.Stroke = new SolidColorBrush(Colors.Green);//颜色
customLine.StrokeThickness = 3;//线粗
this.radChart.DefaultView.ChartArea.Annotations.Add(customLine);
3、后台代码(自定义颜色区域):
MarkedZone redZone = new MarkedZone();
redZone.StartY = 25;
redZone.EndY = 35;
redZone.Background = new SolidColorBrush(Color.FromArgb(255, 248, 109, 90));
this.radChart.DefaultView.ChartArea.Annotations.Add(redZone);