Hello.
I'm using TeeChart Pro 4.2018.12.17.
As far as I can see I cannot set axis title position via TeeChart Editor:
By default it is located in the middle of the axis (to the left of labels in case of left axis and below labels in case of bottom axis):
But I want it to be at the end of axis (in a row with labels): above "1.9" label for the left axis and to the right of "04.04.2018/1/1" label for the bottom axis.
How can I do this?
Thank you.
Howto set axis title posistion to the end of the axis?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Howto set axis title posistion to the end of the axis?
Hello,
One way would be draw your custom text directly to the Chart, e.g.
Code: Select all
private void InitializeChart()
{
Bar bar = new Bar(tChart1.Chart);
bar.FillSampleValues();
tChart1.AfterDraw += TChart1_AfterDraw1;
}
private void TChart1_AfterDraw1(object sender, Graphics3D g)
{
Rectangle leftRect = tChart1.Axes.Left.AxisRect();
string leftTitle = "left title";
g.TextOut(leftRect.X - Utils.Round(g.TextWidth(leftTitle)), leftRect.Y, leftTitle);
Rectangle bottomRect = tChart1.Axes.Bottom.AxisRect();
string bottomTitle = "bottom title";
g.TextOut((bottomRect.X + bottomRect.Width) - Utils.Round(g.TextWidth(bottomTitle)), bottomRect.Y, bottomTitle);
}
Best Regards,
Christopher Ireland / 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 |
Re: Howto set axis title posistion to the end of the axis?
Christopher wrote: ↑Mon Jan 14, 2019 8:20 amOne way would be draw your custom text directly to the Chart, e.g.
- I've slightly modified your code to make axis title be above all axis labels and to respect tChart1.Axis.Left.Title.Font setting (which is Calibri, 12pt, Bold in my case):
Looks like that approach ignores the fact that left axis title font is bold:
Code: Select all
g.TextOut((tChart1.Axis.Left.Title.Font, bottomRect.X + bottomRect.Width) - Utils.Round(g.TextWidth(bottomTitle)), bottomRect.Y - 15, bottomTitle);
- Just interesting - why do you use Utils.Round(g.TextWidth(bottomTitle)) instead of Math.Round(g.TextWidth(bottomTitle))?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Howto set axis title posistion to the end of the axis?
Hello,
Utils.Round is simply a little sugar to save having to type out those extra five characters
You can rectify this by setting the Font properties in the AfterDraw event, e.g.
Code: Select all
private void TChart1_AfterDraw1(object sender, Graphics3D g)
{
g.Font.Bold = true;
g.Font.Name = "Calibri";
g.Font.Size = 12;
Rectangle leftRect = tChart1.Axes.Left.AxisRect();
string leftTitle = "left title";
g.TextOut(leftRect.X - Utils.Round(g.TextWidth(leftTitle)), leftRect.Y, leftTitle);
Rectangle bottomRect = tChart1.Axes.Bottom.AxisRect();
string bottomTitle = "bottom title";
g.TextOut((bottomRect.X + bottomRect.Width) - Utils.Round(g.TextWidth(bottomTitle)), bottomRect.Y, bottomTitle);
}
Using Math.Round would mean having to code an additional cast to Int32, e.g.
Code: Select all
g.TextOut(leftRect.X - (int)Math.Round(g.TextWidth(leftTitle)), leftRect.Y, leftTitle);
Best Regards,
Christopher Ireland / 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 |
Re: Howto set axis title posistion to the end of the axis?
Thx, it's working now.