绑定List <keyvaluepair>时,折线图只有一个轴

时间:2016-01-15 10:57:33

标签: c# wpf charts wpftoolkit

好吧,我有下一个问题 - 在页面上我有WPF工具包图表,折线图。

var array = cssString.match(/([ a-zA-Z])*(\d*[.]?\d*)*/g);

当我转到此页面时,lineChart可以为空,即使数据绑定到图表<chartingToolkit:Chart Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0" Name="lineChart" Visibility="Hidden" VerticalAlignment="Top" Height="150" BorderThickness="3" BorderBrush="#FF423852"> <chartingToolkit:Chart.Axes> <chartingToolkit:LinearAxis Orientation="Y" Minimum="0"> <chartingToolkit:LinearAxis.MajorTickMarkStyle> <Style TargetType="Line"> <Setter Property="Stroke" Value="#bdb3ce" /> <Setter Property="StrokeThickness" Value="1" /> <Setter Property="Y1" Value="-4" /> <Setter Property="Y2" Value="4" /> </Style> </chartingToolkit:LinearAxis.MajorTickMarkStyle> </chartingToolkit:LinearAxis> </chartingToolkit:Chart.Axes> <chartingToolkit:Chart.Style> <Style TargetType="Control"> <Setter Property="Foreground" Value="#bdb3ce" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="chartingToolkit:Chart"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Name="BorderParent"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <!-- Use a nested Grid to avoid possible clipping behavior resulting from ColumnSpan+Width=Auto --> <Grid Grid.Row="1" Margin="5 15"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <primitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}"> <Grid x:Name="PlotArea" Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}"/> <Border Canvas.ZIndex="10" BorderBrush="#61596f" BorderThickness="1 0 0 1" Margin="5 2"/> <Canvas Background="Transparent" x:Name="activePointGridLines" Margin="5 0 0 0" /> </primitives:EdgePanel> </Grid> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </chartingToolkit:Chart.Style> <chartingToolkit:Chart.LegendStyle> <Style TargetType="Control"> <Setter Property="Width" Value="0" /> </Style> </chartingToolkit:Chart.LegendStyle> <chartingToolkit:Chart.PlotAreaStyle> <Style TargetType="Grid"> <Setter Property="Background" Value="Transparent" /> <Setter Property="SnapsToDevicePixels" Value="True" /> </Style> </chartingToolkit:Chart.PlotAreaStyle> <chartingToolkit:LineSeries IndependentValuePath="Key" DependentValuePath="Value" ItemsSource="{Binding}" DataContext="{Binding}" Margin="5.5,0,0,3" DataPointStyle="{StaticResource SeriesDataPointStyle}" Name="nLineSeries"> <chartingToolkit:LineSeries.IndependentAxis> <chartingToolkit:CategoryAxis Orientation="X" MajorTickMarkStyle="{StaticResource ChartMajorTickMarkStyle}"/> </chartingToolkit:LineSeries.IndependentAxis> </chartingToolkit:LineSeries> </chartingToolkit:Chart> 。我注意到,当图表为空时,它只有一个轴(Y轴)。当图表不为空时,绑定图表后有两个轴。

DataContext

什么可能导致此行为以及如何解决?

1 个答案:

答案 0 :(得分:0)

问题已解决。

我已删除<chartingToolkit:LineSeries IndependentValuePath="Key" DependentValuePath="Value" ItemsSource="{Binding}" DataContext="{Binding}" Margin="5.5,0,0,3" DataPointStyle="{StaticResource SeriesDataPointStyle}" Name="nLineSeries"> <chartingToolkit:LineSeries.IndependentAxis> <chartingToolkit:CategoryAxis Orientation="X" MajorTickMarkStyle="{StaticResource ChartMajorTickMarkStyle}"/> </chartingToolkit:LineSeries.IndependentAxis> </chartingToolkit:LineSeries>

来自

<chartingToolkit:LineSeries IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" Margin="5.5,0,0,3" DataPointStyle="{StaticResource SeriesDataPointStyle}" />

DataContext

现在将数据绑定到图表的ItemsSource,但绑定到存在的LineSeries _lineChart.DataContext = valueList;

来自

var lineChartSerie = (LineSeries)_lineChart.Series.FirstOrDefault();
if (lineChartSerie != null) lineChartSerie.ItemsSource = valueList;

{{1}}