I'm trying to draw the bottom axis labels offset a few pixels from their normal position. I thought I might be able to set the axis text to transparent, then in GetAxisLabel read the location and labelText and draw it a few pixels over.
However ValueIndex is not valid unless the the label style is set to Text (I need it set to Value).
Any way to get ValueIndex valid? Or alternate ways to offset the axis labels? This is a real-time graph and the x-axis scale may change often.
Offset axis labels
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
To be able to change axes labels position you should use custom labels as told on this message. Could you please have a look at it?
To be able to change axes labels position you should use custom labels as told on this message. Could you please have a look at it?
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 |
I think custom labels will work for me, but I need to find a way to avoid label overlap. This code:
Doesn't work - All the coordinates for the label, Right, Left, Top, size, etc.. are 0. How can I determine the location and size of a custom label?
Code: Select all
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
tChart1.Header.Text="";
Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;
for (int i=1; i<tChart1.Axes.Left.Labels.Items.Count; ++i)
{
CurrentLabel = tChart1.Axes.Left.Labels.Items[i];
PreviousLabel = tChart1.Axes.Left.Labels.Items[i-1];
tChart1.Header.Text=tChart1.Header.Text+" "+CurrentLabel.Top.ToString();
if (CurrentLabel.Top+CurrentLabel.Height == PreviousLabel.Top)
{
CurrentLabel.Visible=false;
}
}
}
Well I kinda sorta answered my own question. This code works for me, I assume a certain label width but for my needs that is OK.
Code: Select all
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Steema.TeeChart.AxisLabelItem CurrentLabel;
int labelWidth = 40;
int labelCount = (int)(tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum);
int chartWidth = tChart1.Size.Width;
int canShow = chartWidth / labelWidth;
int showEvery = labelCount / canShow;
if ( showEvery < 1 ) showEvery = 1;
for (int i = 0; i < labelCount; ++i)
{
CurrentLabel = tChart1.Axes.Bottom.Labels.Items[i];
if ( i % showEvery == 0 )
{
CurrentLabel.Visible = true;
}
else
{
CurrentLabel.Visible = false;
}
}
}
However, I have one additional issue with my particular graph. It has a black background, and while the grid lines show up in the correct location the labels themselves do not appear.
This works fine in a small test project, any ideas why the label text would not be shown? The labels displayed when I was not using custom labels.
This works fine in a small test project, any ideas why the label text would not be shown? The labels displayed when I was not using custom labels.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gp,
Could it be that the labels are in black font and this makes the labels not visible with black background?
Could it be that the labels are in black font and this makes the labels not visible with black background?
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 |
Yes, I found that the custom label color has to be set explicitly when one is added, if you want something other than black.
Also, to work in my application I had to enable/disable the labels in BeforeDrawAxis, rather than AfterDraw. Here is the final solution:
Thanks for the tips!
Code: Select all
Steema.TeeChart.AxisLabelItem item = tChart1.Axes.Bottom.Labels.Items.Add(i + (width / 2), i.ToString());
item.Font.Color = tChart1.Axes.Bottom.Labels.Color;
Code: Select all
private void tChart1_BeforeDrawAxes(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
Steema.TeeChart.AxisLabelItem CurrentLabel;
int labelWidth = 40; // Hardcoded width of label text.
// The count is how many of our labels fit within the range of the graph.
int labelCount = (int)(tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum);
int chartWidth = tChart1.Size.Width;
int canShow = chartWidth / labelWidth;
int showEvery = labelCount / canShow;
if ( showEvery < 1 ) showEvery = 1;
for (int i = 0; i < tChart1.Axes.Bottom.Labels.Items.Count; ++i)
{
CurrentLabel = tChart1.Axes.Bottom.Labels.Items[i];
if ( i % showEvery == 0 )
{
CurrentLabel.Visible = true;
}
else
{
CurrentLabel.Visible = false;
}
}
}