Legend with Alignment = Button not centering
Legend with Alignment = Button not centering
I'm using the latest version of TeeChart .Net on windows CE using the compact framework.
I am using a bottom aligned legend like so:
chartTank.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
I expected the legen to be centered horizontally, but that isn't the case. See Below:
I am using a bottom aligned legend like so:
chartTank.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
I expected the legen to be centered horizontally, but that isn't the case. See Below:
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Legend with Alignment = Button not centering
Hello,
This issue has already been added to our bugs database and has been fixed.
In the meantime, you can use custom positioning to rectify the issue:
This issue has already been added to our bugs database and has been fixed.
In the meantime, you can use custom positioning to rectify the issue:
Code: Select all
private void InitializeChart()
{
Random rnd = new Random();
tChart1.Aspect.View3D = false;
for (int j = 0; j < 2; j++)
{
var barProduct = new Steema.TeeChart.Styles.Bar();
for (int i = 0; i < 10; i++)
{
barProduct.Add(rnd.Next(0, 100));
}
tChart1.Series.Add(barProduct);
}
tChart1.Legend.Alignment = LegendAlignments.Bottom;
tChart1.Legend.CustomPosition = true;
tChart1.Legend.Left = Utils.Round(tChart1.Width / 2.5);
tChart1.Legend.Top = tChart1.Height - 40;
tChart1.Panel.MarginBottom = 10;
}
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: Legend with Alignment = Button not centering
Is there any way to Remove the box around the legend?
In a perfect world, I would like to position the legend like so
Is that possible?
In a perfect world, I would like to position the legend like so
Is that possible?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Legend with Alignment = Button not centering
Possibly the easiest thing to do here is to draw your own "legend", e.g.tms4000 wrote:Is there any way to Remove the box around the legend?
In a perfect world, I would like to position the legend like so
Is that possible?
Code: Select all
private void InitializeChart()
{
Random rnd = new Random();
tChart1.Aspect.View3D = false;
for (int j = 0; j < 2; j++)
{
var barProduct = new Steema.TeeChart.Styles.Bar();
for (int i = 0; i < 10; i++)
{
barProduct.Add(rnd.Next(0, 100));
}
tChart1.Series.Add(barProduct);
}
tChart1.Legend.Visible = false;
tChart1.Panel.MarginBottom = 10;
tChart1.AfterDraw +=tChart1_AfterDraw;
}
void tChart1_AfterDraw(object sender, Graphics3D g)
{
DrawMyLegend(g, tChart1.Axes.Left.Position, tChart1.Axes.Bottom.Position + 30, tChart1[0]);
DrawMyLegend(g, tChart1.Axes.Left.Position + g.Chart.ChartRect.Width - 50, tChart1.Axes.Bottom.Position + 30, tChart1[1]);
}
private void DrawMyLegend(Graphics3D g, int left, int top, Series series)
{
g.Brush.Color = series.Color;
g.Rectangle(Utils.FromLTRB(left, top, left + 10, top + 10));
g.TextOut(left + 15, top - 2, series.Title);
}
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: Legend with Alignment = Button not centering
Can I remove the box around it without resorting to drawing the legend myself?
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Legend with Alignment = Button not centering
To do that you need:tms4000 wrote:Can I remove the box around it without resorting to drawing the legend myself?
Code: Select all
tChart1.Legend.Transparent = true;
Code: Select all
tChart1.Legend.ColumnWidthAuto = false;
tChart1.Legend.ColumnWidths = new int[2] { 10, 300 };
tChart1.Legend.Symbol.Width = 5;
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: Legend with Alignment = Button not centering
I'm using the following code on setup:
chartTank.Legend.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
chartTank.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
chartTank.Legend.CustomPosition = true;
chartTank.Legend.Top = chartTank.Height - 68;
chartTank.Panel.MarginBottom = 15;
And depending on certain conditions, I'm changing the series that are visible. After I alter the series visibility, I try to reposition the legend with the following code:
chartTank.Legend.Left = Convert.ToInt32((chartTank.Width - chartTank.Legend.Width) / 2.0);
However it seems like the chartTank.Legend.Width isn't recalculated until after this line, therefore the legend get positioned based on the previous legend width.
Is there anyway to force the legend to recalculate it's width before I set it's position?
chartTank.Legend.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
chartTank.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
chartTank.Legend.CustomPosition = true;
chartTank.Legend.Top = chartTank.Height - 68;
chartTank.Panel.MarginBottom = 15;
And depending on certain conditions, I'm changing the series that are visible. After I alter the series visibility, I try to reposition the legend with the following code:
chartTank.Legend.Left = Convert.ToInt32((chartTank.Width - chartTank.Legend.Width) / 2.0);
However it seems like the chartTank.Legend.Width isn't recalculated until after this line, therefore the legend get positioned based on the previous legend width.
Is there anyway to force the legend to recalculate it's width before I set it's position?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Legend with Alignment = Button not centering
Hello,
You may also be interested in using the GetLegendRect event, where you can change its dimensions using the e.Rectangle argument, for example:
Try calling TChart.Draw() method before this line, for example:tms4000 wrote: Is there anyway to force the legend to recalculate it's width before I set it's position?
Code: Select all
chartTank.Draw();
chartTank.Legend.Left = Convert.ToInt32((chartTank.Width - chartTank.Legend.Width) / 2.0);
Code: Select all
void tChart1_GetLegendRect(object sender, Steema.TeeChart.GetLegendRectEventArgs e)
{
Rectangle rect = e.Rectangle;
rect.Width /= 2;
e.Rectangle = rect;
}
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 |