Page 1 of 1
Legend with Alignment = Button not centering
Posted: Mon Jun 09, 2014 5:26 pm
by 15669348
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:
Re: Legend with Alignment = Button not centering
Posted: Tue Jun 10, 2014 10:19 am
by Christopher
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:
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;
}
Re: Legend with Alignment = Button not centering
Posted: Wed Jun 11, 2014 2:20 pm
by 15669348
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?
Re: Legend with Alignment = Button not centering
Posted: Wed Jun 11, 2014 2:53 pm
by Christopher
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?
Possibly the easiest thing to do here is to draw your own "legend", e.g.
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);
}
Re: Legend with Alignment = Button not centering
Posted: Wed Jun 11, 2014 3:32 pm
by 15669348
Can I remove the box around it without resorting to drawing the legend myself?
Re: Legend with Alignment = Button not centering
Posted: Wed Jun 11, 2014 4:11 pm
by Christopher
tms4000 wrote:Can I remove the box around it without resorting to drawing the legend myself?
To do that you need:
Code: Select all
tChart1.Legend.Transparent = true;
which you could use in addition to e.g.
Code: Select all
tChart1.Legend.ColumnWidthAuto = false;
tChart1.Legend.ColumnWidths = new int[2] { 10, 300 };
tChart1.Legend.Symbol.Width = 5;
Re: Legend with Alignment = Button not centering
Posted: Thu Jun 12, 2014 2:04 am
by 15669348
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?
Re: Legend with Alignment = Button not centering
Posted: Thu Jun 12, 2014 1:50 pm
by narcis
Hello,
tms4000 wrote:
Is there anyway to force the legend to recalculate it's width before I set it's position?
Try calling TChart.Draw() method before this line, for example:
Code: Select all
chartTank.Draw();
chartTank.Legend.Left = Convert.ToInt32((chartTank.Width - chartTank.Legend.Width) / 2.0);
You may also be interested in using the
GetLegendRect event, where you can change its dimensions using the
e.Rectangle argument, for example:
Code: Select all
void tChart1_GetLegendRect(object sender, Steema.TeeChart.GetLegendRectEventArgs e)
{
Rectangle rect = e.Rectangle;
rect.Width /= 2;
e.Rectangle = rect;
}