首页 > 解决方案 > 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"/>

我将非常感谢你的努力

标签: c#wpfcolorstelerik

解决方案


您可以使用 Telerik 的PointTemplateSelector。这允许在代码中动态定制每个点。

在此处输入图像描述


推荐阅读