使用ControlTemplate的WPF Toolkit Chart不显示我的LineSeries

时间:2014-11-19 05:00:20

标签: c# wpf xaml charts series

我使用发布的here

示例创建了一个自定义图表

我的Xaml看起来像这样:

<chartingToolkit:Chart  Name="lineChart" Loaded="lineChart_Loaded">
    <chartingToolkit:Chart.Template>                
        <ControlTemplate TargetType="chartingToolkit:Chart">

            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" >
                <Grid>

                    <chartingToolkit:LineSeries x:Name="LineSeries"/>


                    <chartingprimitives:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" Margin="10,30,10,10">
                        <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" />
                        <Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="1" Background="White"/>
                    </chartingprimitives:EdgePanel>

                    <datavis:Legend x:Name="Legend" Title="{TemplateBinding LegendTitle}" Style="{TemplateBinding LegendStyle}" Background="#FFF8DC"
                                        VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,30,15,0" />


                    <Border Background="#FFF8DC" BorderBrush="Black" BorderThickness="0.5" CornerRadius="5,5,5,5"
                            VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,10,0" Width="200">
                        <Label x:Name="LABLE_Description" />
                    </Border>
                </Grid>
            </Border>

        </ControlTemplate>
    </chartingToolkit:Chart.Template>      
</chartingToolkit:Chart>

在Chart_Loaded事件中,我插入了代码:

List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
valueList.Add(new KeyValuePair<string, int>("Developer", 6000));
valueList.Add(new KeyValuePair<string, int>("Misc", 2000));
valueList.Add(new KeyValuePair<string, int>("Tester", 5000));
valueList.Add(new KeyValuePair<string, int>("QA", 3000));
valueList.Add(new KeyValuePair<string, int>("Project Manager", 4000));

LineSeries lineSeries = new LineSeries();
lineSeries.DependentValuePath = "Value";
lineSeries.IndependentValuePath = "Key";
lineSeries.IsSelectionEnabled = true;
lineSeries.ItemsSource = valueList;
lineChart.Series.Add(lineSeries);

但是当我运行应用程序时,我看到一张空图表...... 谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

从一个默认的chartingToolkit开始:主xaml中的图表。您似乎删除了实际填充该系列的内容。

这对我有用:

<Grid>
    <chartingToolkit:Chart Name="lineChart" Loaded="lineChart_Loaded" />
</Grid>