我有两个问题:
为什么
Color
绑定不起作用。您能否提供设置绑定以动态管理颜色的正确方法?现在我
SplineAreaSeries
是静态的并在 XAML 中初始化。如果我想再添加 10 个系列,那么最好、更优雅的方法是什么?
XAML:
<telerik:RadCartesianChart x:Name="xRevChart">
<telerik:RadCartesianChart.Grid>
<telerik:CartesianChartGrid MajorLinesVisibility="XY" MajorXLineDashArray="10.5"
MajorXLinesRenderMode="All"/>
</telerik:RadCartesianChart.Grid>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis></telerik:LinearAxis>
</telerik:RadCartesianChart.VerticalAxis>
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:CategoricalAxis></telerik:CategoricalAxis>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:SplineAreaSeries Name="xSplineArea1" CategoryBinding="XValue" ValueBinding="YValue">
<telerik:SplineAreaSeries.Fill>
<SolidColorBrush Color="{Binding Color}"/>
</telerik:SplineAreaSeries.Fill>
</telerik:SplineAreaSeries>
<telerik:SplineAreaSeries Name="xSplineArea2" CategoryBinding="XValue" ValueBinding="YValue">
<telerik:SplineAreaSeries.Fill>
<SolidColorBrush Color="{Binding Color}"/>
</telerik:SplineAreaSeries.Fill>
</telerik:SplineAreaSeries>
</telerik:RadCartesianChart>
代码:
public class ChartDataClass
{
public double XValue { get; set; }
public double YValue { get; set; }
public Color Color { get; set; }
}
List<ChartDataClass> list1 = new List<ChartDataClass>();
for (int i = 0; i < 20; i++)
{
ChartDataClass c = new ChartDataClass();
c.XValue = i;
c.YValue = rand.NextDouble() * 100;
c.Color = Colors.Blue;
list1.Add(c);
}
xRevChart.Series[1].ItemsSource = list1;