通过 DispatcherTimer 可以刷新Chart界面:
后台 C# 代码:
- public partial class MainWindow : Window
- {
- public double[,] D_Data;
- DispatcherTimer dt;
- public MainWindow()
- {
- InitializeComponent();
- D_Data = new double[20, 20];
- Random rdm = new Random();
- for (int r = 0; r < 20; r++)
- {
- for (int c = 0; c < 20; c++)
- {
- D_Data[r, c] = rdm.Next(-10, 10);
- }
- }
- c1Chart3D1.Children[0].ZData = D_Data;
- dt = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(2) };
- dt.Tick += new EventHandler(dt_Tick);
- dt.Start();
- }
- void dt_Tick(object sender, EventArgs e)
- {
-
- D_Data = new double[20, 20];
- Random rdm = new Random();
- for (int r = 0; r < 20; r++)
- {
- for (int c = 0; c < 20; c++)
- {
- D_Data[r, c] = rdm.Next(-10, 10);
- }
- }
- c1Chart3D1.Children.Clear();
- c1Chart3D1.Children.Add(new C1.WPF.C1Chart3D.GridDataSeries() { ZData = D_Data });
- c1Chart3D1.UpdateLayout();
- }
- }
复制代码
XAML 代码:
- <my:C1Chart3D Margin="10,10,12,12" Name="c1Chart3D1">
- <my:GridDataSeries/>
- </my:C1Chart3D>
复制代码 |