TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
-
dave
- Newbie
- Posts: 35
- Joined: Fri Feb 24, 2006 12:00 am
Post
by dave » Thu Apr 19, 2007 4:45 am
Hi,
I'm using a timer on my Windows form to refresh the chart every few minutes. This is done by having the timer to call for the following function:
Code: Select all
public void Reload()
{
RegionDataHelper dh = new RegionDataHelper();
DataTable dt;
tChart1.AutoRepaint = false;
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Line priceLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
Steema.TeeChart.Styles.Line demandLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
priceLine.VertAxis = Steema.TeeChart.Styles.VerticalAxis.Right;
priceLine.Title = "RRP";
priceLine.Color = Color.Blue;
demandLine.Title = "Demand";
demandLine.Color = Color.Brown;
demandLine.LinePen.Width = 3;
tChart1.Header.Text = RegionName;
tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM/yy HH:mm";
dt = dh.GetData(RegionName);
foreach (DataRow dr in dt.Rows)
{
priceLine.Add(Convert.ToDateTime(dr["settlementdate"].ToString()), Single.Parse(dr["rrp"].ToString()));
demandLine.Add(Convert.ToDateTime(dr["settlementdate"].ToString()), Single.Parse(dr["totaldemand"].ToString()));
}
colourLine1 = new ColorLine(tChart1.Chart);
colourLine1.Active = true;
colourLine1.Axis = tChart1.Axes.Bottom;
colourLine1.AllowDrag = true;
colourLine1.Value = DateTime.Now.ToOADate();
tChart1.AutoRepaint = true;
tChart1.Refresh();
}
The problem is when the timer invokes the function in subsequent times, it'll add a new legend to the chart. It could be adding new series into the charts as well, but I've yet to test that.
As you could see, I have tried setting AutoRepaint to false but it didn't work.
Please advise. Thanks.
-
dave
- Newbie
- Posts: 35
- Joined: Fri Feb 24, 2006 12:00 am
Post
by dave » Mon Apr 23, 2007 7:31 am
Hi Narcis,
I've just sent the files to you. I've put it under my name Poh, Dave is my boss actually.
Cheers.
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Mon Apr 23, 2007 9:53 am
Hi Poh,
Thanks for the example.
Your problem happens because you are adding new series to the chart every time the timer event is fired.
You have 2 options here:
1. Remove all chart's series every time the event is fired:
Code: Select all
public void Reload()
{
tChart1.AutoRepaint = false;
tChart1.Aspect.View3D = false;
tChart1.RemoveAllSeries();
Steema.TeeChart.Styles.Line firstLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
Steema.TeeChart.Styles.Line secondLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
firstLine.Title = "First Line";
firstLine.Color = Color.Blue;
secondLine.Title = "Second Line";
secondLine.Color = Color.Yellow;
firstLine.FillSampleValues(100);
secondLine.FillSampleValues(100);
tChart1.Header.Text = "Test Chart";
tChart1.AutoRepaint = true;
tChart1.Invalidate();
//tChart1.Refresh();
}
2. If series already exist just clear them:
Code: Select all
public void Reload()
{
tChart1.AutoRepaint = false;
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Line firstLine;
Steema.TeeChart.Styles.Line secondLine;
if (tChart1.Series.Count == 0)
{
firstLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
secondLine = new Steema.TeeChart.Styles.Line(tChart1.Chart);
}
else
{
firstLine = (Steema.TeeChart.Styles.Line)tChart1[0];
secondLine = (Steema.TeeChart.Styles.Line)tChart1[1];
firstLine.Clear();
secondLine.Clear();
}
firstLine.Title = "First Line";
firstLine.Color = Color.Blue;
secondLine.Title = "Second Line";
secondLine.Color = Color.Yellow;
firstLine.FillSampleValues(100);
secondLine.FillSampleValues(100);
tChart1.Header.Text = "Test Chart";
tChart1.AutoRepaint = true;
tChart1.Invalidate();
//tChart1.Refresh();
}
-
dave
- Newbie
- Posts: 35
- Joined: Fri Feb 24, 2006 12:00 am
Post
by dave » Tue Apr 24, 2007 12:25 am
Thanks Narcis, it's working great!
-
dave
- Newbie
- Posts: 35
- Joined: Fri Feb 24, 2006 12:00 am
Post
by dave » Tue Apr 24, 2007 1:52 am
Oopps, I spoke too soon. In my actual code, I have plotted a vertical line using Colorline function, which was omitted from my sample code.
The additional code is at the end of the code:
Code: Select all
...
colourLine1 = new ColorLine(tChart1.Chart);
colourLine1.Active = true;
colourLine1.Axis = tChart1.Axes.Bottom;
colourLine1.AllowDrag = false;
colourLine1.Value = DateTime.Now.ToOADate();
tChart1.AutoRepaint = true;
tChart1.Invalidate();
I've used tChart1.Series.RemoveAllSeries() as suggested and it seemed to stop the series from replotting, but I'm not sure what I should use to stop the ColorLine from replotting.
Please advise. Thanks.
-
dave
- Newbie
- Posts: 35
- Joined: Fri Feb 24, 2006 12:00 am
Post
by dave » Tue Apr 24, 2007 3:09 am
I think I found the solution. I used tChart1.Tools.Clear() and it seemed to do the trick.
Cheers!