Stack two bars on top of each other....

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bushtor
Newbie
Newbie
Posts: 1
Joined: Wed Jun 26, 2019 12:00 am

Stack two bars on top of each other....

Post by bushtor » Tue May 26, 2020 5:57 pm

Hello,

This is my first time post here :-)
License: TeeChart VCL Std with source...

I am creating the Current.jpg bargraphs programmatically in Delphi Rio and display them in Fast-Report VCL. I haven't found a way to stack two bars on the same X position like in Goal.jpg screenshot..

Is this possible using my version of TeeChart? If yes, can I also smooth my red Current.jpg curve graph so it looks more like the blue one in Goal.jpg..?

Thanks a lot for help or comments on this.

best regards Tor
Attachments
Goal.jpg
Goal.jpg (27.93 KiB) Viewed 6717 times
Current.jpg
Current.jpg (141.81 KiB) Viewed 6717 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Stack two bars on top of each other....

Post by Yeray » Thu May 28, 2020 11:18 am

Hello,

Here a simple example:
Project1_2020-05-28_13-23-16.png
Project1_2020-05-28_13-23-16.png (17.87 KiB) Viewed 6699 times

You basically need to set the TBarSeries MultiBar property mbStacked and use an additional TLineSeries with a TSmoothingFunction to show a smoothed line while still showing only a few (source) points:

Code: Select all

uses Series, TeeSpLine;

procedure TForm1.FormCreate(Sender: TObject);
var i,j: Integer;
    SourceSeries: TPointSeries;
    SmoothSeries: TLineSeries;
    SmoothFun: TSmoothingFunction;
begin
  Chart1.View3D:=False;
  Chart1.Gradient.Visible:=False;
  Chart1.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;
  Chart1.Legend.Hide;
  Chart1.Axes.Bottom.Grid.Hide;
  Chart1.Axes.Left.Grid.Hide;

  for i:=0 to 1 do
    with TBarSeries(Chart1.AddSeries(TBarSeries)) do
    begin
      FillSampleValues(12);
      MultiBar:=mbStacked;
      Marks.Hide;
      if i=0 then
      begin
        for j:=0 to Count-1 do
            YValue[j]:=-YValue[j];
      end;
    end;

  SourceSeries:=TPointSeries.Create(Chart1);
  with SourceSeries do
  begin
    FillSampleValues(12);
    Pointer.Show;
    Pointer.Color:=clWhite;
    Pointer.Style:=psCircle;
  end;

  SmoothSeries:=TLineSeries(Chart1.AddSeries(TLineSeries));
  with SmoothSeries do
  begin
    ShowInEditor:=False;
    ShowInLegend:=False;
    SmoothFun:=TSmoothingFunction.Create(Chart1);
    SmoothFun.Interpolate:=True;
    SmoothFun.Factor:=8;
    SetFunction(SmoothFun);

    DataSource:=SourceSeries;
  end;

  Chart1.AddSeries(SourceSeries);
  SmoothSeries.Color:=SourceSeries.Color;
  SourceSeries.Pointer.Pen.Color:=SmoothSeries.Color;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply