Hi,
I'm trying to get the bar width in order to decide how wide to draw the bar outline (if the bar is too thin then I'd like to set the outline width to 0).
As I understand, the chart calculates the bar width to fit the chart width.
Is there a way to get the actual bar width (i.e. the width that will be drawn eventually). I've tried to use bar.BarBounds.Width or bar.CustomBarWidth but these are always 0.
Thanks in advance
Itai
Getting the bar width
Re: Getting the bar width
Hi Itai,
You have to retrieve this information once the chart has been drawn.
The following seems to work fine for me here:
You have to retrieve this information once the chart has been drawn.
The following seems to work fine for me here:
Code: Select all
Steema.TeeChart.Styles.Bar bar1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.FillSampleValues();
tChart1.Draw();
tChart1.Header.Text = bar1.BarBounds.Width.ToString();
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Getting the bar width
Hi Yeray,
Perhaps I should elaborate on my problem a bit more.
Usualy, I'd like to draw the bars with a rather thick outline so I initialize my bars with:
The problem is that sometimes my chart contains a lot of bars and so each bar is very thin. As a result the user can only see the outlines and not the bars themselves. Instead of seeing different bars with different colors the user sees all the bars in white (the outline color). You can see this in the image below: (Note that the legend shows various series with various colors.)
In such a case I'd like to reduce the outline width, something like:
If I change the width of the bar outline after draw, it only takes effect in the next draw (e.g. if I minimize the window and restore it again).
I'd rather not draw the chart twice (first time just to get the bars' width and second time to draw the chart with the correct border width) as this causes flickering and also because I'm afraid that draw may be an expensive opperation in certain situations.
My qustion is, is there a way to retrieve the bar's width and set the outline width according to it before draw? or pehaps there's a way to set the outline width to be relative to the bar's width?
Thanks,
Itai
Perhaps I should elaborate on my problem a bit more.
Usualy, I'd like to draw the bars with a rather thick outline so I initialize my bars with:
Code: Select all
bar.Pen.Width = 2;
Code: Select all
bar.Pen.Width = 0;
I'd rather not draw the chart twice (first time just to get the bars' width and second time to draw the chart with the correct border width) as this causes flickering and also because I'm afraid that draw may be an expensive opperation in certain situations.
My qustion is, is there a way to retrieve the bar's width and set the outline width according to it before draw? or pehaps there's a way to set the outline width to be relative to the bar's width?
Thanks,
Itai
Re: Getting the bar width
Hi qcrnd,
You could force the chart to be drawn and show or hide the pen depending on the bars width. For example:
You could force the chart to be drawn and show or hide the pen depending on the bars width. For example:
Code: Select all
tChart1.Draw();
if (sender.BarBounds.Width < 5)
sender.Pen.Visible = false;
else
sender.Pen.Visible = true;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Getting the bar width
Hi Yeray,
I think you didn't understand. If I change the pen AFTER draw then this will be visible only in the next draw. I don't want to draw the chart twice because this causes flickering (i.e. the user can see the chart being drawn once with thick bar outlines and then drawn again with thin bar outlines) and also because it can take a long time to draw the chart.
What I would like is to be able to set the bar.Pen.Width according to what bar.BarBounds.Width is going to be without drawing the chart twice. I understand that the final bar width is being calculated only in draw. I was hoping that there's some way to know the bar width BEFORE or WHILE draw and set the border width accordingly. Perhaps some callback after the bar width has been calculated and before the chart has been drawn.
Is there any such way to set bar.Pen.Width according to bar.BarBounds.Width without drawing the chart twice?
Thanks,
Itai
I think you didn't understand. If I change the pen AFTER draw then this will be visible only in the next draw. I don't want to draw the chart twice because this causes flickering (i.e. the user can see the chart being drawn once with thick bar outlines and then drawn again with thin bar outlines) and also because it can take a long time to draw the chart.
What I would like is to be able to set the bar.Pen.Width according to what bar.BarBounds.Width is going to be without drawing the chart twice. I understand that the final bar width is being calculated only in draw. I was hoping that there's some way to know the bar width BEFORE or WHILE draw and set the border width accordingly. Perhaps some callback after the bar width has been calculated and before the chart has been drawn.
Is there any such way to set bar.Pen.Width according to bar.BarBounds.Width without drawing the chart twice?
Thanks,
Itai
Re: Getting the bar width
Hi Itai,
Doing it at GetBarStyle event, you'll check it after drawing each bar, so it should be ok for all the bars except for the first one:
Another option would be calculating the widths that the bars will have manually before they'll be drawn, known the size of the chart:
Doing it at GetBarStyle event, you'll check it after drawing each bar, so it should be ok for all the bars except for the first one:
Code: Select all
Steema.TeeChart.Styles.Bar bar1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.FillSampleValues(200);
bar1.Marks.Visible = false;
bar1.Pen.Width = 2;
bar1.Pen.Color = Color.White;
tChart1.Axes.Bottom.SetMinMax(-5, 300);
bar1.GetBarStyle += new Steema.TeeChart.Styles.CustomBar.GetBarStyleEventHandler(bar1_GetBarStyle);
}
void bar1_GetBarStyle(Steema.TeeChart.Styles.CustomBar sender, Steema.TeeChart.Styles.CustomBar.GetBarStyleEventArgs e)
{
if (sender.BarBounds.Width < 5)
sender.Pen.Visible = false;
else
sender.Pen.Visible = true;
}
Code: Select all
Steema.TeeChart.Styles.Bar bar1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.FillSampleValues(200);
bar1.Marks.Visible = false;
bar1.Pen.Width = 2;
bar1.Pen.Color = Color.White;
tChart1.Axes.Bottom.SetMinMax(-5, 300);
if ((tChart1.ClientRectangle.Width / (tChart1.Axes.Bottom.Maximum - tChart1.Axes.Bottom.Minimum)) < 5)
bar1.Pen.Visible = false;
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |