Stepping as stacked area series to/from zero values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Stepping as stacked area series to/from zero values

Post by Test Always #? » Mon Mar 20, 2023 8:34 pm

I've spent hours working on this and getting it working, only to find another where it doesn't work.

In the attached demo, a chart is created with area series that should step down to zero when the next value is zero or from zero when the previous value was zero. I can get it working some of the time, but I can't get it working for all four options.

In the demo, there are two methods for creating the char: UpdateChart1 and UpdateChart2, Clicking on the "Illustration #..." radio button produces different results. The combo box on the top right selects which chart method is used. UpdateChart1 shows the chart correctly but doesn't do the stepping. UpdateChart2 has different problems, depending upon which illustration is selected. (The chart is supposed to have a smooth upper line, showing income in retirement).

How can I achieve this?

Much appreciated,

Ed Dressel
Attachments
Stepped Area.zip
(8.99 KiB) Downloaded 1652 times

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

Re: Stepping as stacked area series to/from zero values

Post by Yeray » Thu Mar 23, 2023 12:07 pm

Hello,

Could you please draw what's the result you'd like to obtain? I'm not sure to understand it.
Test Always #? wrote:
Mon Mar 20, 2023 8:34 pm
UpdateChart2 has different problems, depending upon which illustration is selected. (The chart is supposed to have a smooth upper line, showing income in retirement).
I see in UpdateChart2 you are adding zeros to draw stairs/steps (instead of slopes) when going from/to a zero. But I'm not sure to see what's wrong with that approach.
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

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Thu Mar 23, 2023 5:09 pm

Thank you for your response.

Here is a link to an image that I have working (sorry, I could not get the "img" tags to work and display the image in the preview):

http://www.tbinc.com/misc/A.jpg

Image

When the cash flows get more complex, it falls apart--e.g., incomes starting and stopping. It took me a lot of work to get this one working.

I need them to step down, not slide down.

Does that make sense?

Ed Dressel

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

Re: Stepping as stacked area series to/from zero values

Post by Yeray » Fri Mar 24, 2023 6:24 pm

Hello,

The link to the image seems broken.
You can use attachments.
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

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Fri Mar 24, 2023 11:09 pm

Sorry, the link should have been:

Image

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Stepping as stacked area series to/from zero values

Post by Marc » Wed Mar 29, 2023 11:39 am

Hello Ed,

Yeray may have a better understanding of this but he's unavailable for comment for a few days. My interpretation of the Chart, technique UpdateChart1, is that, TeeChartwise, it's fine according to the data input, as you pointed out in your first post.

With respect to your other comment:
but doesn't do the stepping
If we were to step the whole series (stairs true), it comes nowhere near to a coherent plot so I guess it's just a step down (looking at the image you've sent-over) at the end that is required, rather than a slope from the last 'highish' value to zero. It occurs to me that a cheat might be required, that a zero value, added at the same x location as the previous 'highish' value could resolve the issue.

I haven't test-coded it but it is codeable I think via a cchart event such as OnBeforeDrawSeries,
ie.
...if value = zero then insert zero value at x of last non-zero value

then an extra point, the same as the next value, will likely be needed for the other series at that location to keep all series in sync.

Recapping, the last high value of each series will also have a zero value at the same x location. ...just a proposal for now.

Regards,
Marc
Steema Support

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Stepping as stacked area series to/from zero values

Post by Marc » Thu Mar 30, 2023 7:12 am

...another thing we can do is check if perhaps we could add a 'drop-off' close feature for area series, wherein the series drops off to zero at the last value with a non-zero value.

It's a bit tricky because it is a very specific case and unlikely to be generically applicable to other cases where drop-off may not be to zero, or whether to include 'drop-on', ..and to only apply at the the very end of a series, etc. We'll take a look.

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Wed Apr 05, 2023 8:47 pm

..another thing we can do is check
That would be a great feature! This would make sense for null values--or negative values. But I have spent days trying to figure this out.

Much appreciated,

Ed Dressel

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Stepping as stacked area series to/from zero values

Post by Marc » Tue Apr 18, 2023 7:13 am

Hello Ed,

Checking this to see how it can be done. If the rules are:

1. If a value is followed by a zero then no direct join is made to the next point, rather a step downwards is made at the x-location of the last non-zero value.
2. If the predecessor to a value is zero, no direct join is made rather a step up is made at the x-location where the non-zero value occurs.

That would give this chart (a simulation) for the data in the example project:
step_simulation1.jpg
step_simulation1.jpg (135.08 KiB) Viewed 33236 times
Does that agree with what you expect to see?

With thanks.
Regards,
Marc

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Stepping as stacked area series to/from zero values

Post by Marc » Tue Apr 18, 2023 4:33 pm

We see a obstacle to us adding the step-up/down as a generic feature because for stacked charts, if another series in the stack has values and another doesn't, a stack could show up as hollow

ie.
step_simulation2.jpg
step_simulation2.jpg (74.55 KiB) Viewed 33214 times
which is, data-wise, true to the values of the blue series, but aesthetically not particularly attractive,

or .... to fill-down the blue.

ie.
step_simulation3.jpg
step_simulation3.jpg (72.99 KiB) Viewed 33214 times
which is aesthetically easier on the eye, but data-wise gives the impression that, for example, the penultimate blue value is very large, which it isn't.

We are up for thinking this through further and working with any feedback, but at the moment we feel that a generic implementation wouldn't be true to the data in many cases.

Regards,
Marc
Steema Support

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Thu Apr 20, 2023 3:38 pm

I think this would depend upon what type of data is being illustrated. For our need (retirement income data) it works well and is what we want to see, but for other data, I can see it being a problem (and probably stacked bars work better).

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

Re: Stepping as stacked area series to/from zero values

Post by Yeray » Wed Apr 26, 2023 6:23 am

Hello,

I made a simple example trying to replicate the image you posted above.

Here the result:
Project1_2023-04-26_08-58-41.png
Project1_2023-04-26_08-58-41.png (15.18 KiB) Viewed 33013 times
And the code to make it:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i, tmp: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Hover.Hide;
  Chart1.Gradient.Visible:=False;
  Chart1.Walls.Back.Hide;
  Chart1.Color:=clWhite;
  Chart1.Axes.Bottom.Grid.Hide;
  Chart1.Legend.Pen.Hide;
  Chart1.Legend.Shadow.Hide;
  Chart1.Legend.VertSpacing:=15;
  Chart1.Title.Hide;
  Chart1.Axes.Left.Title.Text:='Monthly Income';
  Chart1.Axes.Bottom.Title.Text:='Years in Retirement';
  Chart1.Legend.Font.Size:=12;
  Chart1.Axes.Left.Title.Font.Size:=15;
  Chart1.Axes.Bottom.Title.Font.Size:=15;
  Chart1.Axes.Left.LabelsFont.Size:=12;
  Chart1.Axes.Bottom.LabelsFont.Size:=12;
  Chart1.Axes.Left.Axis.Width:=1;
  Chart1.Axes.Left.MinorTicks.Hide;
  Chart1.Axes.Bottom.Axis.Width:=1;
  Chart1.Axes.Bottom.Ticks.Hide;
  Chart1.Axes.Bottom.MinorTicks.Hide;

  with TAreaSeries(Chart1.AddSeries(TAreaSeries)) do
  begin
    Color:=$CA9044;
    Title:='Social Security';
    Pen.Hide;
    AreaLinesPen.Hide;
    MultiArea:=maStacked;

    tmp:=3800;
    for i:=0 to 21 do
    begin
      if (i=14) then
         AddXY(i, tmp);

      AddXY(i, tmp);
      Inc(tmp, 50);
    end;
  end;

  with TAreaSeries(Chart1.AddSeries(TAreaSeries)) do
  begin
    Color:=$3ACDA7;
    Title:='Retirement Plan';
    Pen.Hide;
    AreaLinesPen.Hide;
    MultiArea:=maStacked;

    tmp:=2500;
    for i:=0 to 21 do
    begin
      if (i=14) then
      begin
        AddXY(i, 2000);
        tmp:=0;
      end;

      AddXY(i, tmp);
    end;
  end;

  with TAreaSeries(Chart1.AddSeries(TAreaSeries)) do
  begin
    Color:=$9998FF;
    Title:='Projected Shortfall';
    Transparency:=20;
    Pen.Hide;
    AreaLinesPen.Hide;
    MultiArea:=maStacked;

    tmp:=0;
    for i:=0 to 21 do
    begin
      if (i=14) then
      begin
        AddXY(i, 500);
        tmp:=2500;
      end;

      AddXY(i, tmp);
    end;
  end;
end;
I haven't tried that data with the code in your "method 2", but the idea is very similar. Doesn't it work for you?
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

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Mon May 08, 2023 3:02 pm

That will work for this chart, but I need a solution that works for various scenarios when I don't know the data.

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

Re: Stepping as stacked area series to/from zero values

Post by Yeray » Tue May 09, 2023 12:54 pm

Hello,

Could you please draw what would you'd like to obtain in those situations where you are failing to obtain it?
You sent us a great project to test with 4 data scenarios. That's fantastic but I'm not sure to understand what's the goal in each of those scenarios.
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

Test Always #?
Newbie
Newbie
Posts: 20
Joined: Thu Jan 13, 2022 12:00 am

Re: Stepping as stacked area series to/from zero values

Post by Test Always #? » Mon May 15, 2023 3:13 pm

They should produce stepped area charts. In all the cases in the demo, the top line should be steady/slowly increasing (like the image provided earlier).

Does that make sense?

Post Reply