我要绑定到图表的数据表中有 2 列。Visifire 示例显示了使用 observablecollection 的示例,但我不知道如何将数据表与 observablecollection 相关联(我认为这是我的问题)。我创建了一个示例来可视化。我正在为图表使用visifire。
public MainWindow()
{
InitializeComponent();
dtBandwidth = dsBandwidth.Tables.Add();
dtBandwidth.Columns.Add("ID", typeof(int));
dtBandwidth.Columns.Add("Time", typeof(double));
dtBandwidth.Columns.Add("Value", typeof(double));
dataGrid1.ItemsSource = dtBandwidth.DefaultView;
DataSeries ds = new DataSeries();
ds.RenderAs = RenderAs.Line;
ds.DataSource = dtBandwidth???; //i know this is wrong. what should i do?
DataMapping dm = new DataMapping();
dm.MemberName = "XValue";
dm.Path = "Time";
ds.DataMappings.Add(dm);
dm = new DataMapping();
dm.MemberName = "YValue";
dm.Path = "Value";
ds.DataMappings.Add(dm);
chart1.Series.Add(ds);
chart1.DataContext = dtBandwidth???; //i know this is wrong. what should i do?
}
private void button1_Click(object sender, RoutedEventArgs e)
{
dtBandwidth.Rows.Add(1, 1.0, 5.2);
dtBandwidth.Rows.Add(2, 2.1, 5.1);
dtBandwidth.Rows.Add(3, 3.2, 5.3);
dtBandwidth.Rows.Add(4, 4.3, 5.4);
dtBandwidth.Rows.Add(5, 5.4, 5.5);
}
这是xaml。
<Grid>
<DataGrid AutoGenerateColumns="True" Height="311" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top" Width="143" />
<my:Chart HorizontalAlignment="Left" Margin="149,0,0,0" Name="chart1" VerticalAlignment="Top" Height="311" Width="354" />
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="186,328,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
我确实尝试在官方的visifire论坛上提问,但支持人员只是懒惰(当我告诉他们我已经看过示例时,它告诉我看示例。另外,部分代码是从示例中复制的) .
这种事情让我想放弃visifire并寻找最好的替代方案,最好有良好的文档和支持。欢迎任何建议。