Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法获取WPFToolkit图表以显示数据(引发异常)_C#_Wpf_Charts - Fatal编程技术网

C# 无法获取WPFToolkit图表以显示数据(引发异常)

C# 无法获取WPFToolkit图表以显示数据(引发异常),c#,wpf,charts,C#,Wpf,Charts,经过几个小时的失败尝试,我希望有人能在这里帮助我。我跟随了一篇文章,介绍了如何在WPFToolkit线形图中简单地显示数据: 所以我有一张图表: <chartingToolkit:Chart x:Name="myChart" Title="Power Graph" Background="YellowGreen" Foreground="DarkBlue" VerticalAlignment="Top" Margin="16,36

经过几个小时的失败尝试,我希望有人能在这里帮助我。我跟随了一篇文章,介绍了如何在WPFToolkit线形图中简单地显示数据:

所以我有一张图表:

<chartingToolkit:Chart x:Name="myChart" Title="Power Graph" Background="YellowGreen" 
                             Foreground="DarkBlue" VerticalAlignment="Top" Margin="16,36,20,0" Height="432"  IsEnabled="True">
                <chartingToolkit:LineSeries Title="SolarCell"  
                                    ItemsSource="{Binding}" 
                                    DependentValueBinding="{Binding Path=Value}" 
                                    IndependentValueBinding="{Binding Path=Key}"
                                    IsSelectionEnabled="True">
                    <chartingToolkit:LineSeries.IndependentAxis>
                        <chartingToolkit:LinearAxis Orientation="X" Title="Time (Mins)" Interval="5"  />
                    </chartingToolkit:LineSeries.IndependentAxis>
                    <chartingToolkit:LineSeries.DependentRangeAxis>
                        <chartingToolkit:LinearAxis Orientation="Y" Title="Power (W)"/>
                    </chartingToolkit:LineSeries.DependentRangeAxis>
                </chartingToolkit:LineSeries>
            </chartingToolkit:Chart>
C代码:

Dictionary<string, float> a = new Dictionary<string, float>();
this.myChart.DataContext = a;

void timer_Tick(object sender, EventArgs e)
        {
            this.a.Add(this.elapsedTime.ToString(),meter.GetResult());
           elapsedTime++;

        }
运行时,我遇到以下异常:

“System.InvalidOperationException”类型的未处理异常 在System.Windows.Controls.DataVisualization.Toolkit.dll中发生

附加信息:无法使用指定的独立轴。这 可能是由于轴的未设置方向属性

相关线程:相关和解决方案:使用Dispatchermer和ObservableCollection