Hi,
I'm trying to make a bar chart with text labels on the left axis. But when i resize the window the label font size is not adjusted. Is there a solution for this problem?
Here is some sample code i'm using:
InitializeComponent();
chartController1.Chart = tChart1;
tChart1.Aspect.View3D = false;
this.tChart1.Chart.Legend.Visible = false;
this.tChart1.Chart.Axes.Bottom.Visible = false;
horizBar1 = new Steema.TeeChart.Styles.HorizBar(this.tChart1.Chart);
horizBar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Percent;
tChart1.Axes.Left.Labels.Align = Steema.TeeChart.AxisLabelAlign.Opposite;
horizBar1.Add(150, "bar label 1",Color.Red);
horizBar1.Add(120, "bar label 2", Color.Black);
horizBar1.Add(100, "bar label 3", Color.Blue);
horizBar1.Marks.Visible = false;
this.tChart1.Chart.Axes.Left.Labels.AutoSize = true;
horizBar1.YValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending;
this.tChart1.Walls.Visible = false;
this.tChart1.Chart.Series.Add(horizBar1);
When resizing the window the label text size is not changed. I would like to have the font size of the labels smaller when the window size gets smaller.
I also tried it with: (tChart1.Axes.Left.Labels.Items.Add(2, "bar label 1")).Font.Size = 16;
But then i need to recalculate the font size manually in the SizeChanged event?
Axes Labels
Re: Axes Labels
Hi SPS,
Try using OnResize event as follows. The following code assigns the event:
And this calculates the left axis labels font size proportionally to the left axis size:
Try using OnResize event as follows. The following code assigns the event:
Code: Select all
this.tChart1.Resize += new EventHandler(tChart1_Resize);
Code: Select all
void tChart1_Resize(object sender, EventArgs e)
{
this.tChart1.Draw();
this.tChart1.Axes.Left.Labels.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 10));
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Axes Labels
This formula doesnt seem to work correct, when i only change the height of the window the font size gets bigger until the mark text doesnt fit in the window anymore. What exactly is IEndPos and IStartPos ?
Also when i have set the property: horizBar1.Marks.Transparent = true;
And then in the resize event method i do something like: int a = horizBar1.Marks.Items.Font.Size; the transparant seems to be gone since i see the mark
rectangle again.
Also when i have set the property: horizBar1.Marks.Transparent = true;
And then in the resize event method i do something like: int a = horizBar1.Marks.Items.Font.Size; the transparant seems to be gone since i see the mark
rectangle again.
Re: Axes Labels
Hi SPS,
I suppose that our projects have different responses because we have different Dock styles for our charts, or maybe there is another property I'm missing to set. So, could you please attach a simple example project we can run as-is to reproduce the problem here?
IStartPos and IEndPos are the number of pixels from the top (top if we are talking about vertical axes, left if we are talking about horizontal axes) of the chart to the Start or the End position of the axis. You can play with those values through the chartcontroller (Chart/Axes/Position tab) to see the effect of changing their values.
I suppose that our projects have different responses because we have different Dock styles for our charts, or maybe there is another property I'm missing to set. So, could you please attach a simple example project we can run as-is to reproduce the problem here?
IStartPos and IEndPos are the number of pixels from the top (top if we are talking about vertical axes, left if we are talking about horizontal axes) of the chart to the Start or the End position of the axis. You can play with those values through the chartcontroller (Chart/Axes/Position tab) to see the effect of changing their values.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Axes Labels
I have attached a simple horbar test project
- Attachments
-
- HorBarTest.zip
- HorBar chart test with resize labels, resizing doesn't work good
- (11.35 KiB) Downloaded 555 times
Re: Axes Labels
I have solved the problem by setting a max font size, but it would be nice to have an option in teechart that automatic calculates the label sizes and mark label sizes based on the window screen width/height.
Re: Axes Labels
Hi SPS,
We'll consider to add a new property to make this automatically. In the meanwhile, the following code seems to work better in your application and doesn't loop into your series:
We'll consider to add a new property to make this automatically. In the meanwhile, the following code seems to work better in your application and doesn't loop into your series:
Code: Select all
void tChart1_Resize(object sender, EventArgs e)
{
tChart1.Draw(this.CreateGraphics());
horizBar1.Marks.Transparent = true;
this.tChart1.Axes.Left.Labels.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 5));
horizBar1.Marks.Font.Size = ((this.tChart1.Axes.Left.IEndPos - this.tChart1.Axes.Left.IStartPos) / (horizBar1.Count * 5));
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |