我正在使用WPF工具包在AreaSeries圖表上顯示數據,但沒有出現。不知道我做錯了什麼。請幫忙/建議。如何顯示WPF Toolkit AreaSeries圖表上的數據?
下面是XAML代碼:
<Window xmlns:chart="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
x:Class="GRAPHPrototype.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GRAPHPrototype"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<chart:Chart Name="chart1">
</chart:Chart>
</Grid>
和C#代碼:
public partial class MainWindow : Window
{
static List<Ready4LOS> Ready4LOS = new List<Data.Ready4LOS>();
public MainWindow()
{
InitializeComponent();
InitChart();
SampleData();
chart1.DataContext = Ready4LOS;
}
private void SampleData()
{
Ready4LOS.Add(new Data.Ready4LOS() { Case = 5, Time = DateTime.Now.AddMinutes(-75) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 15, Time = DateTime.Now.AddMinutes(-65) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 5, Time = DateTime.Now.AddMinutes(-55) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 8, Time = DateTime.Now.AddMinutes(-45) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 22, Time = DateTime.Now.AddMinutes(-35) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 35, Time = DateTime.Now.AddMinutes(-25) });
Ready4LOS.Add(new Data.Ready4LOS() { Case = 4, Time = DateTime.Now.AddMinutes(-05) });
}
private void InitChart()
{
System.Windows.Data.Binding indi = new System.Windows.Data.Binding("Case");
System.Windows.Data.Binding dep = new System.Windows.Data.Binding("Time");
AreaSeries ares = new AreaSeries();
ares.IndependentValueBinding = indi;
ares.DependentValueBinding = dep;
DateTimeAxis dta = new DateTimeAxis();
dta.Interval = 10;
dta.IntervalType = DateTimeIntervalType.Minutes;
dta.Title = "Time";
dta.Orientation = AxisOrientation.X;
dta.Minimum = DateTime.Now.AddMinutes(-80);
dta.Maximum = DateTime.Now;
LinearAxis yaxis = new LinearAxis();
yaxis.Minimum = 0;
yaxis.Interval = 2;
yaxis.Title = "Case";
yaxis.Orientation = AxisOrientation.Y;
chart1.Axes.Add(yaxis);
chart1.Axes.Add(dta);
chart1.Series.Add(ares);
}
}
我有這種格式
class Ready4LOS : INotifyPropertyChanged
{
int _case;
DateTime _time;
public int Case
{
get
{
return _case;
}
set
{
_case = value;
NotifyPropertyChanged("Case");
}
}
public DateTime Time
{
get
{
return _time;
}
set
{
_time = value;
NotifyPropertyChanged("Time");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
感激,如果某一個格式化的問題,如果不這樣做妥善由我:( – rvsingh42
感謝Funk重新格式化。 – rvsingh42