由于某些点的空值,RadCartesianChart没有被绘制

时间:2014-09-08 08:55:15

标签: windows-8 charts telerik windows-8.1 radchart

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

例如它有3个项目:

值1 = 10

值2 = null

值3 = 20

它的StrokeMode =“AllButPlotLine”,

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

此致

1 个答案:

答案 0 :(得分:1)

RadChart(RadCartesianChart)支持空(null / NaN)值。以下是使用MVVM模式进行探索的示例。请注意,Oranges没有代表值。

  

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

MainPage.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; }
}

ViewModel.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; }
}