Page 1 of 1
How to Wrap Long Text in Chart Headet/SubHeader?
Posted: Mon Sep 20, 2010 8:50 am
by 13045482
I've a long text more than 200 characters. When I assign this text to the Subheader my Subheader text is clipped from both Sides as Subheader alignment is Center. Please suggest some way so that text is wrapped automatically.
Re: How to Wrap Long Text in Chart Headet/SubHeader?
Posted: Mon Sep 20, 2010 3:17 pm
by 10050769
Hello Neelam,
I have made a example where text is placed automatically, using methods for treat strings and AfterDraw Event. Please, check if next code works as you want:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
public void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Bar bar = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar.FillSampleValues(10);
bar.XValues.DateTime = true;
bar.Marks.Visible = false;
tChart1.AfterDraw = new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
tChart1.Draw();
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
tChart1.SubHeader.Visible = true;
tChart1.SubHeader.Text = AddText();
tChart1.SubHeader.TextAlign = StringAlignment.Far;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int lenght1 = tChart1.SubHeader.Text.Length / 4;//number of IstarIndex
string s1 = tChart1.SubHeader.Text.Substring(lenght1 * 0, tChart1.SubHeader.Text.Length / 4);
string s2 = tChart1.SubHeader.Text.Substring(lenght1 * 1, tChart1.SubHeader.Text.Length / 4);
string s3 = tChart1.SubHeader.Text.Substring(lenght1 * 2, tChart1.SubHeader.Text.Length / 4);
string s4 = tChart1.SubHeader.Text.Substring(lenght1 * 3, tChart1.SubHeader.Text.Length / 4);
sb.Append(s1 "\n");
sb.Append(s2 "\n");
sb.Append(s3 "\n");
sb.Append(s4 "\n");
tChart1.SubHeader.Text = sb.ToString();
}
private String AddText()
{
String Text = "Creating charts is really easy to do. Just drop a Chart component on your form and double-click it to show the editor dialog. First steps with the editor dialog are clicking the Add button to choose a chart style (series) from the Gallery..";
return Text;
}
I hope will helps.
Thanks,
Re: How to Wrap Long Text in Chart Headet/SubHeader?
Posted: Thu Sep 23, 2010 7:35 am
by 13045482
If I follow this example, I'll need to fix the number of lines (in the example you gave it 4) need to be displayed in the SubHeader. I can't fix the number of lines because of the following reasons
1. Text Length & Number of lines can vary according to screen resolution.
2. Text Length can vary according to Window Size.
3. Text Length depends on the width occupied by the characters. e.g. 'i' occupies less space compared to '%' or '&'. So number of character that can be placed in a line is also varies.
I hope my doubt is clear to you. Please suggest some other solution like Auto Size of Windows Label control.
Re: How to Wrap Long Text in Chart Headet/SubHeader?
Posted: Fri Sep 24, 2010 3:48 pm
by 10050769
Hello Neelam,
Sorry for the delay. I have made a simple project that I think you can use in your application:
Code: Select all
public void InitializeChart()
{
tChart1.Aspect.View3D = false;
// tChart1.Dock = DockStyle.Fill;
Steema.TeeChart.Styles.Bar bar = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar.FillSampleValues(10);
bar.XValues.DateTime = true;
bar.Marks.Visible = false;
tChart1.AfterDraw = new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
tChart1.Draw();
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
int i = 0;
string s;
int lenght1;
int canvastextsize;
tChart1.SubHeader.Visible = true;
tChart1.SubHeader.Text = AddText();
tChart1.SubHeader.TextAlign = StringAlignment.Center;
Rectangle rect = tChart1.Chart.ChartRect;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
canvastextsize = ((int)g.TextWidth(tChart1.SubHeader.Font, tChart1.SubHeader.Text))/rect.Width;
lenght1 = tChart1.SubHeader.Text.Length / canvastextsize;
while(i<tChart1.SubHeader.Text.Length)
{
if (tChart1.SubHeader.Text.Length - lenght1> i)
{
s = tChart1.SubHeader.Text.Substring(i, lenght1);
sb.Append(s "\n");
i = lenght1;
}
else
{
lenght1 = tChart1.SubHeader.Text.Length - i;
s = tChart1.SubHeader.Text.Substring(i, lenght1);
sb.Append(s "\n");
i = tChart1.SubHeader.Text.Length;
}
}
tChart1.SubHeader.Text = sb.ToString();
}
private String AddText()
{
String Text = "Creating charts is really easy to do. Just drop a Chart component on your form and double-click it to show the editor dialog. First steps with the editor dialog are clicking the Add button to choose a chart style (series) from the Gallery..";
return Text;
}
Could you please say us if previous code works as you want?
I hope will helps.
Thanks,