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:

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;
}
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 |
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);
}
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 |
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;
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 |
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;
}
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 |