Draw Average TBarSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Draw Average TBarSeries

Post by Calou » Thu Nov 20, 2008 10:20 am

Hello,

With the TAverageFunction is there is a way to draw the average like it
Image

I can draw the average but this is not cutted between the barSeries.

Thank you for help

Regards

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Fri Nov 21, 2008 11:57 am

Hello,

Are you working on this topic? :oops:

Regards

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 21, 2008 12:01 pm

Hi Calou,

Yes, we are working on it. We will get back to you when we have further news.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Nov 24, 2008 8:04 am

Hi Calou,

We have made a sample project doing something similar to what you request. We will send it by e-mail. You just have to remove axes labels and us a custom axis label for each stack group. You'll find a custom axis labels example at All Features\Welcome!\Axes\Labels\Custom labels in the new features demo available at TeeChart's program group.

If this doesn't help you could use custom axes (3 in that case) and associate series to those axes as in your image. Then you just should add an average function for each series.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Mon Nov 24, 2008 11:17 am

Hello,

I have done something like that (i send it on your upload page. Name : Bar.zip).

But i have two problems
How i can do to have the testseries width = the group bar width and center it on each group bar?
If i unchecked series the scale is changed. Is it possible to prevent it?

Thank you for help

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Nov 25, 2008 11:07 am

Hi Calou,
How i can do to have the testseries width = the group bar width and center it on each group bar?
In that case we recommend you to manually calculate average and custom draw it on chart's canvas. You can also use existing average series, disable it and use its value for manually plotting the lines you want. You'll find more information about custom drawing in Tutorial 13 - Custom drawing on the Chart Panel. Tutorials are available at TeeChart's program group. On this forum, using its search feature, you will also find several custom drawing examples.
If i unchecked series the scale is changed. Is it possible to prevent it?
Yes, in that case you have two options:

1. Instead of disabling series set their color to clNone. If you are using legend's checkboxes you should use OnClickLegend event.
2. Set series values to null.

However, for not needing so many customizations you'd better use a custom axis and a single series for each group.

Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Wed Nov 26, 2008 3:05 pm

Hello,

There is no problem to manually calculate average.
On the other hand using custom axis means that on one axis i have all the bar for one project in my case. If i uncheck it in legend, all the bars of one project are hidden. But i don't want it. I have to hidde the bar 1 on project 1, the bar 1 one project 2...
Futhermore i have not find a solution in custom axis to draw the bar side by side.
It would be very interressant for me to draw a line serie (points are calculate to do the average) which is cutted (no problem with addnull) but i am not able to centre it on each project without using custom axes :oops:

Regards

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Wed Nov 26, 2008 4:26 pm

I have done something like it for test.
What do you think about this method (the number of series could be between 1 to n)?

Code: Select all

  Series1.AddXY(0,50);
  Series1.AddXY(1,60);
  Series1.AddXY(2,40);
  Series2.AddXY(0,40);
  Series2.AddXY(1,30);
  Series2.AddXY(2,70);
  Series3.AddNull(0);
  Series3.AddXY(1,70);
  Series3.Addnull(2);

  Chart1.Draw();


  delta_x:=Abs(Series1.XScreenToValue(Series2.CalcXPos(0))-Series1.XScreenToValue(Series1.CalcXPos(0)));
  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(0));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,50);
  Series4.AddXY(x_fin,50);
  Series4.AddNullXY(x_fin,50);

  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(1));
  Series4.AddXY(x_deb,60);
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_fin,60);
  Series4.AddNullXY(x_fin,60);

  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(2));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,60);
  Series4.AddXY(x_fin,60);

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Wed Nov 26, 2008 4:56 pm

By using this method if i do

Series1.AddXY(0,50);
Series2.AddXY(0,40);
Series3.AddNull(0);

the first time, x_deb, delta_x and x_fin equal 0

How could prevent it?

Thank you

Regards

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 28, 2008 9:57 am

Hi Calou,
On the other hand using custom axis means that on one axis i have all the bar for one project in my case. If i uncheck it in legend, all the bars of one project are hidden. But i don't want it. I have to hidde the bar 1 on project 1, the bar 1 one project 2...
When I mentioned that you could set series values to null an option to do this is setting bar's color to clNone, for example:

Code: Select all

  Series1.Color:=clNone;
Or this:

Code: Select all

  for i:=0 to Chart1.SeriesCount - 2 do
  begin
    Chart1[i].ValueColor[0]:=clNone;
  end;
In the code example you posted in your last post, this code would make the first bar of each series not visible.
Futhermore i have not find a solution in custom axis to draw the bar side by side.
In that case you should set bar series like this:

Code: Select all

  Series1.SideMargins:=false;
  Series1.BarWidthPercent:=100;
By using this method if i do

Series1.AddXY(0,50);
Series2.AddXY(0,40);
Series3.AddNull(0);

the first time, x_deb, delta_x and x_fin equal 0

How could prevent it?
Draw method call in the code you posted should prevent this. This code works fine for me here:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var delta_x : Double;
    x_deb   : Double;
    x_fin   : Double;
    i       : Integer;
begin
  Series1.AddXY(0,50);
  Series1.AddXY(1,60);
  Series1.AddXY(2,40);
  Series2.AddXY(0,40);
  Series2.AddXY(1,30);
  Series2.AddXY(2,70);
  Series3.AddNull(0);
  Series3.AddXY(1,70);
  Series3.Addnull(2);

  Chart1.Draw;

  delta_x:=Abs(Series1.XScreenToValue(Series2.CalcXPos(0))-Series1.XScreenToValue(Series1.CalcXPos(0)));
  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(0));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,50);
  Series4.AddXY(x_fin,50);
  Series4.AddNullXY(x_fin,50);

  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(1));
  Series4.AddXY(x_deb,60);
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_fin,60);
  Series4.AddNullXY(x_fin,60);

  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(2));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,60);
  Series4.AddXY(x_fin,60);
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Fri Nov 28, 2008 10:34 am

Thank you Narcis for your answer

If i write this code :

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  delta_x,x_deb,x_fin:double;
begin
  Chart1.LeftAxis.Automatic:=FALSE;
  Chart1.LeftAxis.Minimum:=0;
  Chart1.LeftAxis.Maximum:=100;
  Chart1.LeftAxis.Increment:=20;

  Series1.AddXY(0,50,'P1');
  Series2.AddXY(0,40,'P1');
  Series3.AddNull(0);

  Chart1.Draw();


  delta_x:=Abs(Series1.XScreenToValue(Series2.CalcXPos(0))-Series1.XScreenToValue(Series1.CalcXPos(0)));
  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(0));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,60);
  Series4.AddXY(x_fin,60);
  Series4.AddNullXY(x_fin,50);

end;
Series4 doesn't appear in spite of Chart.draw

Regards

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 28, 2008 11:07 am

Hi Calou,

This is because series only have on bar. Therefore bottom axis range goes from 0 to 0 and has no option for calculating exact axes positions as you'd like to do. In that case you can add an additional null point to your series and manually set bottom axis scale like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  delta_x,x_deb,x_fin:double;
begin
  Chart1.Axes.Left.Automatic:=FALSE;
  Chart1.Axes.Left.SetMinMax(0,100);
  Chart1.Axes.Left.Increment:=20;

  Series1.AddXY(0,50,'P1');
  Series2.AddXY(0,40,'P1');
  Series3.AddNull(0);

  if Series1.Count=1 then
  begin
    Series1.AddNull('');
    Series2.AddNull('');
    Series3.AddNull('');

    Chart1.Axes.Bottom.SetMinMax(Series1.MinXValue-0.5,Series1.XValue[Series1.Count-2]+0.5);
    //or
    //Chart1.Axes.Bottom.SetMinMax(-0.5,0.5);
  end;

  Chart1.Draw;

  delta_x:=Abs(Series1.XScreenToValue(Series2.CalcXPos(0))-Series1.XScreenToValue(Series1.CalcXPos(0)));
  x_deb:=Series1.XScreenToValue(Series1.CalcXPos(0));
  x_fin:=x_deb+delta_x*3;
  Series4.AddXY(x_deb,60);
  Series4.AddXY(x_fin,60);
  Series4.AddNullXY(x_fin,50);
end;
Hope this helps!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Fri Nov 28, 2008 3:52 pm

Ok Narcis,

It seems that it works good. I draw cutted average series :)

I am going to do more test.

Thank you for help

Regards

Post Reply