c# - WPF Telerik 散点图颜色
问题描述
我是 WPF telerik 技术框架的初学者。我想要自定义颜色到 Telerik 散点图中的点。但是点的颜色没有改变。我应该怎么办?我正在做的事情有什么根本错误吗?这是c#代码
var pallate = ColorPallate();
var PS = new ScatterPointSeries();
var pallaet = new ChartPalette();
PaletteEntryCollection pall = new PaletteEntryCollection();
for (int i = 0; i < data.GetLength(0); i++)
{
ScatterDataPoint point = new ScatterDataPoint();
point.XValue = data[i, XAxisIndex];
point.YValue = data[i, YAaxisIndex];
int value = 0;
if (!float.IsNaN(PredictedResult[i]))
value = System.Convert.ToInt32(PredictedResult[i]);
var filler = new PaletteEntry();
filler.fill(pallate[value]);
pall.Add(filler);
PS.DataPoints.Add(point);
}
pallaet.SeriesEntries.Add(pall);
this.Cross_Plot.Palette = pallaet;
其中 ColorPallate() 提供自定义调色板为
private Brush[] ColorPallate()
{
var pallate = new Brush[15];
pallate[0] = new SolidColorBrush(Colors.Red);
pallate[1] = new SolidColorBrush(Colors.Orange);
pallate[2] = new SolidColorBrush(Colors.Green);
pallate[3] = new SolidColorBrush(Colors.Pink);
pallate[4] = new SolidColorBrush(Colors.Black);
pallate[5] = new SolidColorBrush(Colors.Brown);
pallate[6] = new SolidColorBrush(Colors.Crimson);
pallate[7] = new SolidColorBrush(Colors.DarkOrange);
pallate[8] = new SolidColorBrush(Colors.ForestGreen);
pallate[9] = new SolidColorBrush(Colors.Indigo);
pallate[10] = new SolidColorBrush(Colors.DarkKhaki);
pallate[11] = new SolidColorBrush(Colors.Purple);
pallate[12] = new SolidColorBrush(Colors.Gold);
pallate[13] = new SolidColorBrush(Colors.RosyBrown);
pallate[14] = new SolidColorBrush(Colors.Gray);
return pallate;
}
这是 XMAL 代码
<telerik:RadCartesianChart x:Name="Cross_Plot" Margin="0,51,17,0" VerticalAlignment="Top" Height="472" Grid.Column="2" HorizontalAlignment="Right" Width="1057" Grid.RowSpan="2" >
<telerik:RadCartesianChart.HorizontalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" MajorTickOffset="0"/>
</telerik:RadCartesianChart.HorizontalAxis>
<telerik:RadCartesianChart.VerticalAxis>
<telerik:LinearAxis SmartLabelsMode="SmartStep" ElementBrush="Black" />
</telerik:RadCartesianChart.VerticalAxis>
<telerik:ScatterPointSeries XValueBinding="XValue" YValueBinding="YValue" ItemsSource="{Binding}">
<telerik:ScatterPointSeries.DefaultVisualStyle>
<Style TargetType="Path">
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag.DataItem.Color}" />
<Setter Property="Width" Value="10" />
<Setter Property="Height" Value="10" />
</Style>
</telerik:ScatterPointSeries.DefaultVisualStyle>
</telerik:ScatterPointSeries>
</telerik:RadCartesianChart>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="131,37,0,0" TextWrapping="Wrap" Text="Well points on X Axis" VerticalAlignment="Top" Width="248"/>
<TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="389,35,0,0" TextWrapping="Wrap" Text="Well points on Y axis" VerticalAlignment="Top" Width="243"/>
我将非常感谢你的努力
解决方案
您可以使用 Telerik 的PointTemplateSelector。这允许在代码中动态定制每个点。
推荐阅读
- javascript - 部署后第一次调用 Firebase 云函数总是超时
- swift - 为什么初始分段索引 0 表视图值未在 Swift 中加载?
- jenkins - 在管道中检索注入的构建参数
- sql - 如何查找表中不存在的 id
- angular - Angular 8:已经创建了具有不同配置的平台。请先销毁
- c# - 多个服务器实例中的 WCF 相同服务合同
- angular - 获取对象数组索引号并将其与对象的其他数据一起添加到 mat-table
- python - 从图像中读取文本
- rest - REST 结合了所有记录和一条记录
- matlab - 如何在 MatLab/Octave 中模拟贷款组合?