I'm using the Average tool on a series.
I'm trying to add a label on the left axis at the average value. For now I precalculated the average myself to generate my custom text.
I don't really want to create custom labels. I'm happy with the labels chosen by TeeChart.
I'm just trying to overlay my text over the axis labels. I'd prefer it if the text stayed put if I zoomed in on the bottom axis, but moved if I zoomed in on the left axis.
Which tool would work the best in this situation?
It would be nice if I could just attach my custom text to the Average tool.
Add custom text describing the Average tool.
-
- Newbie
- Posts: 34
- Joined: Thu Sep 04, 2008 12:00 am
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Christo,
One option is using Annotation tool, for example:
The other option is using custom text drawing:
One option is using Annotation tool, for example:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
points1.FillSampleValues();
Steema.TeeChart.Functions.Average avg1 = new Steema.TeeChart.Functions.Average();
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.Function = avg1;
line1.DataSource = points1;
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
Bitmap bmp = tChart1.Bitmap;
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
tChart1.Tools.Clear();
Steema.TeeChart.Tools.Annotation annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
double average = tChart1[1].YValues[0];
annotation1.Text = "Average: " + average.ToString();
int tmp = Convert.ToInt32(g.TextWidth(annotation1.Shape.Font, annotation1.Text));
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginLeft = tmp + 10;
annotation1.Shape.CustomPosition = true;
annotation1.Shape.Left = 10;
annotation1.Shape.Top = tChart1.Axes.Left.CalcPosValue(average);
}
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
points1.FillSampleValues();
Steema.TeeChart.Functions.Average avg1 = new Steema.TeeChart.Functions.Average();
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.Function = avg1;
line1.DataSource = points1;
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
Bitmap bmp = tChart1.Bitmap;
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
double average = tChart1[1].YValues[0];
String myText = "Average: " + average.ToString();
int tmp = Convert.ToInt32(g.TextWidth(g.Font, myText));
tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;
tChart1.Panel.MarginLeft = tmp + 10;
g.TextOut(10, tChart1.Axes.Left.CalcPosValue(average), myText);
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Newbie
- Posts: 34
- Joined: Thu Sep 04, 2008 12:00 am
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Christo,
Not that I can think of but it would be very similar to implementing custom series:
http://www.teechart.net/support/viewtopic.php?t=4309
http://www.teechart.net/support/viewtopic.php?t=4110
http://www.teechart.net/support/viewtopic.php?t=6590
It may also help checking how existing tools are implemented using .NET Reflector with TeeChart.dll.
Not that I can think of but it would be very similar to implementing custom series:
http://www.teechart.net/support/viewtopic.php?t=4309
http://www.teechart.net/support/viewtopic.php?t=4110
http://www.teechart.net/support/viewtopic.php?t=6590
It may also help checking how existing tools are implemented using .NET Reflector with TeeChart.dll.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Newbie
- Posts: 34
- Joined: Thu Sep 04, 2008 12:00 am
Thanks, .NET Reflector is helping a lot to learn TeeChart.
I've managed to implement a custom label which sits on top of the left axis and shows text. I had to use a TextShape to draw the actual text. I was missing something, because when I had two markers, the second one was always drawn black.
I'm now trying to add a similar label, but on the bottom axis. This label needs to be rotated 90 degrees. Unfortunately I couldn't find component in TeeChart which will draw a single label rotated by some angle. Now I'm implementing my own.
Is there maybe such a component I could use?
Thanks for the great support!
I've managed to implement a custom label which sits on top of the left axis and shows text. I had to use a TextShape to draw the actual text. I was missing something, because when I had two markers, the second one was always drawn black.
I'm now trying to add a similar label, but on the bottom axis. This label needs to be rotated 90 degrees. Unfortunately I couldn't find component in TeeChart which will draw a single label rotated by some angle. Now I'm implementing my own.
Is there maybe such a component I could use?
Thanks for the great support!
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Christo,
You could use TeeChart canvas' RotateLabel method for that:
Or in the AfterDraw event:
Hope this helps!
You could use TeeChart canvas' RotateLabel method for that:
Code: Select all
tChart1.Graphics3D.RotateLabel(x, y, Text, angle);
Code: Select all
g.RotateLabel(x, y, Text, angle);
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |