Page 1 of 1
Help - Chart header problem
Posted: Mon Oct 27, 2008 11:42 am
by 9092401
Hi
We have a chart which has a title we assign to Chart.Header.Text with center alignment. The problem is that when the title is long and we resize the graph (make the width smaller), the header does not shrink accordingly although the graph does. Is there an option to make the header font autmatically adjustable to fit the graph width and always be centered . If not what is the best way to handle this problem.
Currently what happens what we see is that the title is cut on the left size altough the alignment is centered. I also see in the debugger that the Left value is negative.
we would like the title font to automatically adjust according to width of the graph.
If this is not possible , we whould consider a tooltip option and have the graph title and ended with "..." and when hovering over it it will give the full name. But for this I would like an example if possible that implements this. we do something with the Legends however I couldnt find a similar callback for the title like GetLegendText is for the legends. also how do I calculate when I need to cut the title myself and by how much.
Please help
Thanks
Ryan.
Posted: Mon Oct 27, 2008 12:54 pm
by narcis
Hi Ryan,
Yes, you can do something like this:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Dock = DockStyle.Fill;
tChart1.Header.Text = "A very very very very very very very very very very very long chart title so that it doesn't fit in chart's dimensions.";
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
tChart1.Draw();
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
double textSize = g.TextWidth(tChart1.Header.Font, tChart1.Header.Text);
while (textSize > tChart1.Width)
{
tChart1.Header.Font.Size--;
textSize = g.TextWidth(tChart1.Header.Font, tChart1.Header.Text);
}
}
Posted: Mon Oct 27, 2008 2:22 pm
by 9092401
Hi
I just tried it , but still I think there is a problem with the center alignment. The title still is cut , The Left is still Negative . I does do something but still the title is not centered and its begining is cut .
Posted: Mon Oct 27, 2008 2:39 pm
by narcis
Hi Ryan,
This works fine for me here using latest v3 release available at the client area. Which TeeChart version are you using? Anyway, This is highly dependant to chart and title dimensions. Also, for proper resizing support you may need to use Resize event too:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Dock = DockStyle.Fill;
tChart1.Header.Text = "A very very very very very very very very very very very long chart title so that it doesn't fit in chart's dimensions.";
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
tChart1.Resize += new EventHandler(tChart1_Resize);
tChart1.Draw();
}
void tChart1_Resize(object sender, EventArgs e)
{
tChart1.Draw();
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
double textSize = g.TextWidth(tChart1.Header.Font, tChart1.Header.Text);
while (textSize > tChart1.Width)
{
tChart1.Header.Font.Size--;
textSize = g.TextWidth(tChart1.Header.Font, tChart1.Header.Text);
}
}
I may also be interested in title's wrapping example I posted
here.
I'll also add the Left=-1 issue to the defect list to be investigated.
Posted: Mon Oct 27, 2008 2:44 pm
by narcis
Hello,
As an update, this issue's tracking number is TF02013488.
Posted: Mon Oct 27, 2008 2:56 pm
by 9092401
Hi
Thanks for the feedback.
I am working with v2 but do you think this is an issue. Once again , my problem is that the Center alignment of the Header (Chart.Header.Alignment = StringAlignment.Center) doesnt seem to work properly and when the graph width becomes small it sets the left position of the header to a negative position and the begining of the title is cut on the left size . Do you know about this problem ? does it also happen in v3
thanks.
Also I would like to know regarding another solution . Is there any callback where I can modify the Header just like there is for the legend (GetLegendText) . I was thinking maybe to add a tooltip and add "..." if the size is too big.
Thanks
Ryan
Posted: Mon Oct 27, 2008 3:10 pm
by narcis
Hi Ryan,
I am working with v2 but do you think this is an issue. Once again , my problem is that the Center alignment of the Header (Chart.Header.Alignment = StringAlignment.Center) doesnt seem to work properly and when the graph width becomes small it sets the left position of the header to a negative position and the begining of the title is cut on the left size . Do you know about this problem ? does it also happen in v3
thanks.
Yes, I think this is the issue that needs to be investigated. I think this also happens in v3.
Also I would like to know regarding another solution . Is there any callback where I can modify the Header just like there is for the legend (GetLegendText) . I was thinking maybe to add a tooltip and add "..." if the size is too big.
Have you looked at the example at the other thread I pointed? This does something similar to what you request but instead of adding "..." divides the header in lines. You could easily modify it to behave as you need.
Posted: Mon Oct 27, 2008 3:43 pm
by 9092401
HI
regarding the center problem , Ok I understand its a bug also in v3 and I will try a way around.
Regarding the example you pointed out , yes I saw it but the thing is that my graph is resizable and so every resize I have to do this , also the user can change the title. In anycase I understand you dont have a callback , I know what to do but if there was a callback each time you are about to display the title , the solution would be more elegant.
Ok - One last issue then . I need a tooltip for the title , because if I cut the title I want a tooltip to display the full title .
1. Must I do all the work myself and create an annotation and check the mouse move etc or is there a a tooltip property I can set for the title somehow ?
2. If I must do the work myself , there is one problem I dont know how to solve, where do I locate the tooltip and how do I make sure that it doesnt go out of the range of the graph and get cut. I can always locate it on the e.X e.Y however if my mouse is close to the edge of the graph then the tooltip will be cut.
what is the best way to do this
Thanks very much for your fast responses.
Ryan.
Posted: Tue Oct 28, 2008 8:22 am
by narcis
Hi Ryan,
Regarding the example you pointed out , yes I saw it but the thing is that my graph is resizable and so every resize I have to do this , also the user can change the title. In anycase I understand you dont have a callback , I know what to do but if there was a callback each time you are about to display the title , the solution would be more elegant.
Ok, I've added your request to the wish-list to be considered for inclusion in next releases.
Ok - One last issue then . I need a tooltip for the title , because if I cut the title I want a tooltip to display the full title .
1. Must I do all the work myself and create an annotation and check the mouse move etc or is there a a tooltip property I can set for the title somehow ?
There's no tool for that, you could use an Annotation tool as you suggest.
2. If I must do the work myself , there is one problem I dont know how to solve, where do I locate the tooltip and how do I make sure that it doesnt go out of the range of the graph and get cut. I can always locate it on the e.X e.Y however if my mouse is close to the edge of the graph then the tooltip will be cut.
what is the best way to do this
You could use mouse events like shown in the code snippet below. However, if annotation's text also doesn't fit in chart's drawing area you may need to perform some kind of text customization as you did with the header.
Code: Select all
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (tChart1.Header.Clicked(e.X, e.Y))
{
Steema.TeeChart.Tools.Annotation annotation1 = new Steema.TeeChart.Tools.Annotation(tChart1.Chart);
annotation1.Text = tChart1.Header.Text;
annotation1.Shape.CustomPosition = true;
annotation1.Shape.Left = 0; //tChart1.Axes.Left.Position;
annotation1.Top = tChart1.Header.Top;
}
else
{
tChart1.Tools.Clear();
}
}
Posted: Tue Oct 28, 2008 8:29 am
by 9092401
Once again thanks very much for your fast and quick response.
I think I have everything I need now , EXCEPT for one issue which I already posted seperately.
HOW CAN I MAKE the annotation act like a TOPMOST , meaning that I dont want it to depend on the graph region for display , I want the whole annotion to be displayed as TopMost above any other control , and also alow it to go beyone the boundaries of the graph.
Thanks.
Posted: Tue Oct 28, 2008 9:06 am
by narcis
Hi Ryan,
You're welcome.
Please see my reply
here.