0

我使用 Telerik RadCartesianChart,它的 ItemSource 绑定在 ObservableCollection 上。

例如它有 3 个项目:

值 1 = 10

值 2 = 空

值 3 = 20

它的 StrokeMode ="AllButPlotLine" ,

由于空值,该线未绘制。我可以画吗?

问候,

4

1 回答 1

1

RadChart (RadCartesianChart) 支持空 (null/NaN) 值。这是一个使用 MVVM 模式的示例供您探索。请注意,橙子没有代表价值。

您的安装文件夹中还有一个空值示例:C:\Program Files (x86)\Telerik\UI for Windows 8.1 XAML Q2 2014\Demos\Examples\Chart\EmptyValues

主页.xaml

 <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <chart:RadCartesianChart Width="700" Height="700">
            <chart:RadCartesianChart.Grid>
                <chart:CartesianChartGrid MajorLinesVisibility="XY" StripLinesVisibility="Y">
                    <chart:CartesianChartGrid.MajorXLineStyle>
                        <Style TargetType="Line">
                            <Setter Property="Stroke" Value="#B45121"/>
                            <Setter Property="StrokeDashArray" Value="4,2"/>
                        </Style>
                    </chart:CartesianChartGrid.MajorXLineStyle>
                    <chart:CartesianChartGrid.MajorYLineStyle>
                        <Style TargetType="Line">
                            <Setter Property="Stroke" Value="#58622D"/>
                            <Setter Property="StrokeDashArray" Value="10,2"/>
                        </Style>
                    </chart:CartesianChartGrid.MajorYLineStyle>
                </chart:CartesianChartGrid>
            </chart:RadCartesianChart.Grid>
            <chart:RadCartesianChart.DataContext>
                <local:ViewModel/>
            </chart:RadCartesianChart.DataContext>
            <chart:RadCartesianChart.HorizontalAxis>
                <chart:CategoricalAxis/>
            </chart:RadCartesianChart.HorizontalAxis>
            <chart:RadCartesianChart.VerticalAxis>
                <chart:LinearAxis/>
            </chart:RadCartesianChart.VerticalAxis>
            <chart:LineSeries ItemsSource="{Binding SeriesData}">
                <chart:LineSeries.CategoryBinding>
                    <chart:PropertyNameDataPointBinding PropertyName="Category"/>
                </chart:LineSeries.CategoryBinding>
                <chart:LineSeries.ValueBinding>
                    <chart:PropertyNameDataPointBinding PropertyName="Value"/>
                </chart:LineSeries.ValueBinding>
            </chart:LineSeries>
        </chart:RadCartesianChart>
    </Grid>

CustomPoint.cs 文件

public class CustomPoint
{
    public string Category { get; set; }
    public double Value { get; set; }
}

视图模型.cs

public class ViewModel
{
    public ViewModel()
    {
        this.SeriesData = new List<CustomPoint>()
        {
            new CustomPoint{ Category = "Apples", Value = 10 },
            new CustomPoint{ Category = "Oranges"},
            new CustomPoint{ Category = "Pears", Value = 15 },
        };
    }
    public List<CustomPoint> SeriesData { get; set; }
}
于 2014-09-08T16:03:57.763 回答