Axis labels for multiple series

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Axis labels for multiple series

Post by Narcís » Thu Jul 30, 2009 3:01 pm

Hi gs,

You need to set Font.Color before drawing to the canvas, for example:

Code: Select all

void Chart_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Rectangle Rect = chart.Chart.Chart.ChartRect;
g.Font.Color = Color.Red;
g.RotateLabel(Rect.Left - customLeftAxis.MaxLabelsWidth() - 30, Rect.Top + 30, customLeftAxis.Title.Text, 90);
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

gs
Newbie
Newbie
Posts: 84
Joined: Mon Mar 20, 2006 12:00 am
Location: US

Re: Axis labels for multiple series

Post by gs » Thu Jul 30, 2009 5:57 pm

Hi Narcis,

The axis title color comes in Red & then becomes white again. I think this could be because I am handling AxesDrawLabel for avaoiding overlap of Axis labels
The code snippet is below


private void customLeftAxis_GetAxisDrawLabel(object sender, GetAxisDrawLabelEventArgs e)
{
//flags indicating overlap with the previous and next labels.
bool overlap;

//Get the axis
Axis axis = (Axis) sender;

if(axis.Labels.Items.Count == 0)
return;

if(!LabelsSorted)
{
axis.Labels.Items.Sort(new AxisItemComparer());
LabelsSorted = true;
}

//get the size of the label text
SizeF currentSize = graphics.MeasureString(e.Text, axis.Labels.Font.DrawingFont);
Rectangle currentRect = new Rectangle(e.X, e.Y + 21, (int) currentSize.Width, (int) currentSize.Height + 3);

//this is needed to get the index value of the label in the array.
double val;

if (!double.TryParse(e.Text, out val))
{
e.DrawLabel = false;
return;
}


//get the AxisLabelItem we are trying to draw.
AxisLabelItem item = new AxisLabelItem(chart.Chart.Chart);
item.Value = val;
int index = axis.Labels.Items.BinarySearch(0, axis.Labels.Items.Count, item, new AxisItemComparer());
//if first or last label set e.DrawLabel to true and return.
if (index == 0 || index == axis.Labels.Items.Count - 1)
{
e.Text = val.ToString("N2");
e.DrawLabel = true;
lastRect = currentRect;
return;
}
if (index < 0 || index > axis.Labels.Items.Count - 1)
{
e.DrawLabel = false;
return;
}

Steema.TeeChart.AxisLabelItem currentLabel = axis.Labels.Items[index];

//if we set visible to false before GetAxisDrawLabel then set e.DrawLabel to false;
if (currentLabel.Visible == false)
e.DrawLabel = false;

//if this axis is vertical then the concern is the height of the label.
if (axis == customLeftAxis && currentRect != lastRect)
{
// check if the label overlaps with the prev drawn label
overlap = currentRect.IntersectsWith(lastRect);
if (overlap || e.DrawLabel == false)
e.DrawLabel = false;
else
{
// set the rect for the last drawn label
e.Text = val.ToString("N2");
lastRect = currentRect;
}
}
}

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Axis labels for multiple series

Post by Narcís » Fri Jul 31, 2009 8:11 am

Hello,

Can you please attach a simple exmaple project we can run "as-is" to reproduce the problem here?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply