6
我很難理解實際上應該發生在LiveCharts上的事情。我有XAML這裏塊:這裏的背後LiveCharts基礎知識 - 如何繪製線條?
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/CPF;component/Images/background-top-cropped2.png" Stretch="None"></ImageBrush>
</Grid.Background>
<lvc:CartesianChart Series="{Binding myData}" LegendLocation="Right" x:Name="myChart">
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Month" Labels="{Binding Labels}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>
和代碼:
public MainWindow()
{
InitializeComponent();
DrawGraphs();
}
public void DrawGraphs()
{
LineSeries mySeries = new LineSeries
{
Values = new ChartValues<int> { 12, 23, 55, 1 }
};
myChart.Series.Add(mySeries);
}
在運行時, 'myChart.Series.Add(mySeries)' 拋出一個空引用異常錯誤。我不確定如何解決這個問題?