TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
-
ljoli
- Newbie
- Posts: 24
- Joined: Wed Apr 28, 2010 12:00 am
- Location: Paris, FRANCE
Post
by ljoli » Fri Jul 16, 2010 3:35 pm
Hi,
----> I would like to build a chart with a CSV file which is update every 100ms.
I began to write the following code :
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Steema.TeeChart.WPF.Styles;
using Steema.TeeChart.WPF.Tools;
using Steema.TeeChart.WPF.Themes;
using Steema.TeeChart.WPF;
using Steema.TeeChart.WPF.Drawing;
using Steema.TeeChart;
using Steema.TeeChart.WPF.Editors;
using Steema.TeeChart.WPF.Export;
using Steema.TeeChart.WPF.Data;
using Steema.TeeChart.WPF.Functions;
using System.Drawing;
using System.Data;
namespace CSV_real_time
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
// disable of view in 3D
this.tChart1.Aspect.View3D = false;
//display or not the legend of chart
this.tChart1.Legend.Visible = false;
tChart1.AutoRepaint = true;
// title of chart
this.tChart1.Header.Text = " CSV file in real time ";
// new fastline of steema library
FastLine fast1;
// add fastline of chart
fast1 = new Steema.TeeChart.WPF.Styles.FastLine(tChart1.Chart);
// Path of CSV file
TextSource textsource1 = new TextSource("C:\\Users\\ljoly\\testone.csv");
// Decimale Separator of each data
textsource1.DecimalSeparator = ',';
// Number of header ( here it is X and Y )
textsource1.HeaderLines = 2;
// Separator of each data
textsource1.Separator = Convert.ToChar("\t");
// link fastline and data on CSV file
fast1.DataSource = textsource1;
// X field data of CSV file
textsource1.Fields.Add(0, "X");
// Y field data of CSV file
textsource1.Fields.Add(1, "Y");
// Active fastlien serie which come from CSV file
textsource1.Series.Active = true;
// link serie of fastline of CSV file
textsource1.Series = fast1;
// make a check of datasource
fast1.CheckDataSource();
}
}
}
And I see an example on the documentation, but it's not really adapt at WPF code.
I use Visual studio 2008 ( WPF code ) with Teechart 3.5.3188.18562
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Mon Jul 19, 2010 7:47 am
Hi ljoli,
I'm not sure to understand what's the exact problem you have with it.
If you have a chart correctly linked to the datasource (it shows the initial data) but it is not refreshing? You could use a timer and call CheckDataSource every timer tick.
-
ljoli
- Newbie
- Posts: 24
- Joined: Wed Apr 28, 2010 12:00 am
- Location: Paris, FRANCE
Post
by ljoli » Mon Jul 19, 2010 8:32 am
Hello Yeray,
In fact, I had a chart with my CSV file but it is not refresh like you say.
I see the different class, in WPF there are "timer" class and "DispatcherTimer". But I don't know really how to use it. On the web I found this code
->
http://social.msdn.microsoft.com/forums ... f7099a936/
Do you have an example in WPF with a timer to create an animate chart ?
Like the example of feature of Teechart:
all features->Welcome->Speed->Real-time charting
Regards,
LJ
-
ljoli
- Newbie
- Posts: 24
- Joined: Wed Apr 28, 2010 12:00 am
- Location: Paris, FRANCE
Post
by ljoli » Mon Jul 19, 2010 9:49 am
So, after some search on the web. I found a solution like below :
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;
using Steema.TeeChart.WPF.Styles;
using Steema.TeeChart.WPF.Tools;
using Steema.TeeChart.WPF.Themes;
using Steema.TeeChart.WPF;
using Steema.TeeChart.WPF.Drawing;
using Steema.TeeChart;
using Steema.TeeChart.WPF.Editors;
using Steema.TeeChart.WPF.Export;
using Steema.TeeChart.WPF.Data;
using Steema.TeeChart.WPF.Functions;
using System.Drawing;
using System.Data;
namespace CSV_real_time
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
///
public partial class Window1 : Window
{
// Declaration of global variable
public Steema.TeeChart.WPF.Styles.FastLine fast1;
//private System.Windows.Threading.DispatcherTimer TimerClock;
// use the DispatcherTimer class for timer application
private DispatcherTimer timer;
public Window1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
// new instance of DispatcherTimer
timer = new DispatcherTimer();
// set interval of timer --> 100 ms
timer.Interval = TimeSpan.FromSeconds(0.100);
// Each tick check datsource of my CSV file
timer.Tick += timer1_Tick;
//Timer timer = new System.Timers.Timer(1000);
timer.Start();
/*
TimerClock = new System.Windows.Threading.DispatcherTimer();
//Creates a timerClock and enables it
TimerClock.Interval = new TimeSpan(0,0,1);
TimerClock.IsEnabled = true;
*/
// disable of view in 3D
this.tChart1.Aspect.View3D = false;
//display or not the legend of chart
this.tChart1.Legend.Visible = false;
tChart1.AutoRepaint = true;
// title of chart
this.tChart1.Header.Text = " CSV file in real time ";
// new fastline of steema library
//FastLine fast1;
// add fastline of chart
fast1 = new Steema.TeeChart.WPF.Styles.FastLine(tChart1.Chart);
// Path of CSV file
TextSource textsource1 = new TextSource("C:\\Users\\ljoly\\testone.csv");
// Decimale Separator of each data
textsource1.DecimalSeparator = ',';
// Number of header ( here it is X and Y )
textsource1.HeaderLines = 2;
// Separator of each data
textsource1.Separator = Convert.ToChar("\t");
// link fastline and data on CSV file
fast1.DataSource = textsource1;
// X field data of CSV file
textsource1.Fields.Add(0, "X");
// Y field data of CSV file
textsource1.Fields.Add(1, "Y");
// Active fastlien serie which come from CSV file
textsource1.Series.Active = true;
// link serie of fastline of CSV file
textsource1.Series = fast1;
// make a check of datasource
fast1.CheckDataSource();
}
void timer1_Tick(object sender, EventArgs e)
{
fast1.CheckDataSource();
}
}
}
is it like that to make a good real time fastline ?
-
Sandra
- Site Admin
- Posts: 3132
- Joined: Fri Nov 07, 2008 12:00 am
Post
by Sandra » Mon Jul 19, 2010 11:01 am
Hello ljoli,
You're right, if you want use timer in WPF you should use a DispatcherTimer. Could you please say us, if this timer works fine for you and solve your problem?
Thanks,
-
ljoli
- Newbie
- Posts: 24
- Joined: Wed Apr 28, 2010 12:00 am
- Location: Paris, FRANCE
Post
by ljoli » Mon Jul 19, 2010 11:04 am
Yes that's works with DispatcherTimer !!
My problem is solved
Thanks
-
Sandra
- Site Admin
- Posts: 3132
- Joined: Fri Nov 07, 2008 12:00 am
Post
by Sandra » Mon Jul 19, 2010 11:20 am
Hello ljoli,
Thanks for your information; I am glad that now works fine for you
.
Thanks,