Combine stacked and line (or other) series?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Jan
Newbie
Newbie
Posts: 24
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany

Combine stacked and line (or other) series?

Post by Jan » Thu Jan 15, 2004 9:02 am

Hello to all,

i have the challenge that i would like to generate a stacked bar or area series (normal / 100%) and overlay it with a normal line (horizontal line/bar/horizontal bar...) series.
The background is a program i wrote for exploring oceanographic data and their relation to biological abundancies of several species.
Due to the nature of this program the amount of columns and rows are not predefined for the stacked part of the chart during development time. Is there a possibility or is there a workaround? I did not find an example that fits to my problem.

Thanks

Jan

Pep
Site Admin
Site Admin
Posts: 3305
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Jan 30, 2004 10:51 am

Hi Jan,

I'm sorry, I'm not sure what are you trying to do. Could you please send an image so I can see it ?

Jan
Newbie
Newbie
Posts: 24
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany

A little more detailed and my solution

Post by Jan » Thu Feb 05, 2004 2:31 pm

Sorry,

i think my text was not very helpful to understand the problem. Finally i managed to create the type of chart i desired (i attached the source below, maybe there is someone out there who has similar ideas and can use it). The greatest part of the solution was to find out that something like StackGroup exists. With that it was no real problem. If calling a second procedure like SetLineXYChart it overlays the bars and can be seen together with the (stacked-)bars. My problem at the beginning was that something confusing happened if i switched all series to e.g. mbStacked, while all having the same StackGroup

But if you look at the code below, maybe you have an idea to enhence it and to generate area plots as well....

Do you have an document how to implement different types of date series (mm/dd/yyyy, dd/mm/yyyy, dd/mm/yyyy hh:mm:ss ..........) and how to check for errors? At the moment the source below is only able to handle values, but for some reasons it could be interesing to use Time , date or both data for the DummyStrY (and further processings) input. I think the challenge is to cover most of the possibilities in a way being as simple as possible.

Some information on the Source:

Datenfeld => A table with the source data
Combine1XListBox => a listbox containing all captions of the columns from Datenfeld/several selections possible
Combine1YCombo => a combobox where to select the other parameter the x-values are depending on
I hope the rest is easy to understand

Procedure TGraphicCanvas.SetCombine1Chart;
Var RunnerX : Integer;
NoOfSeries : Integer;
WhichSeries : Integer;
RunnerY : Integer;
DummyStrX : String;
DummyStrY : String;
ValueX : Double;
ValueY : Double;
ErrorFlagX : Boolean;
ErrorFlagY : Boolean;
Begin
If Form2.Combine1XListBox.SelCount = 0 THen Exit; // if no x parameters selected do nothing
If Not Form2.Combine1VisibleCheckbox.Checked THen Exit; // or if not visible

NoOfSeries := 0;

Comb1HorAxis.Horizontal := True;

For RunnerX := 0 to Form2.Combine1XListBox.Count-1 do // generated number of needed series
Begin
If Form2.Combine1XListBox.Selected [RunnerX] THen
Begin
Case Form2.Combine1TypeCombo.Itemindex of
0 : Begin
Inc (NoOfSeries);
Chart1.AddSeries (TBarSeries.Create (Self));
(Chart1 [Chart1.SeriesCount-1] as TBarSeries).StackGroup := 1;
(Chart1 [Chart1.SeriesCount-1] as TBarSeries).Marks.Visible := False;
(Chart1 [Chart1.SeriesCount-1] as TBarSeries).Title := Form1.DatenFeld.Cells[Runnerx, 0];

Chart1 [Chart1.SeriesCount-1].CustomHorizAxis := Comb1HorAxis;
Chart1 [Chart1.SeriesCount-1].CustomVertAxis := Comb1VertAxis;

Case Form2.Combine1StackTypeCombo.Itemindex of
0 : (Chart1 [Chart1.SeriesCount-1] as TBarSeries).Multibar := mbNone;
1 : (Chart1 [Chart1.SeriesCount-1] as TBarSeries).Multibar := mbStacked;
2 : (Chart1 [Chart1.SeriesCount-1] as TBarSeries).Multibar := mbStacked100;
3 : (Chart1 [Chart1.SeriesCount-1] as TBarSeries).Multibar := mbNone;
end;
end;

1 : Begin
Inc (NoOfSeries);
Chart1.AddSeries (THorizBarSeries.Create (Self));
(Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).StackGroup := 1;
(Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Marks.Visible := False;
(Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Title := Form1.DatenFeld.Cells[Runnerx, 0];

Chart1 [Chart1.SeriesCount-1].CustomHorizAxis := Comb1HorAxis;
Chart1 [Chart1.SeriesCount-1].CustomVertAxis := Comb1VertAxis;

Case Form2.Combine1StackTypeCombo.Itemindex of
0 : (Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Multibar := mbSide;
1 : (Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Multibar := mbStacked;
2 : (Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Multibar := mbStacked100;
3 : (Chart1 [Chart1.SeriesCount-1] as THorizBarSeries).Multibar := mbNone;
end;
end;
end;
end;
end;

For RunnerY := 0 to Form2.Combine1RowListbox.Count-1 do // running through the rows
Begin
If Form2.Combine1RowListbox.Selected [RunnerY] Then // if selected it becomes interesting
Begin

WhichSeries := NoOfSeries; // how many series/parameters have to be processed

For RunnerX := 0 to Form2.Combine1XListBox.Count-1 do // running through the parameters
Begin
If Form2.Combine1XListbox.Selected [RunnerX] THen // if selected it becomes more interesting
Begin
DummyStrX := Form1.DatenFeld.Cells[RunnerX, RunnerY+5];
DummyStrY := Form1.DatenFeld.Cells[Form2.Combine1YCombo.Itemindex, RunnerY+5];

DummyStrX := StringReplace (DummyStrX, ',', DecimalSeparator, [rfReplaceAll]);
DummyStrX := StringReplace (DummyStrX, '.', DecimalSeparator, [rfReplaceAll]);
DummyStrY := StringReplace (DummyStrY, ',', DecimalSeparator, [rfReplaceAll]);
DummyStrY := StringReplace (DummyStrY, '.', DecimalSeparator, [rfReplaceAll]);

ErrorFlagX := Not (TryStrToFloat (DummyStrX, ValueX));
ErrorFlagY := Not (TryStrToFloat (DummyStrY, ValueY));

If ErrorFlagX THen ValueX := StrToFloat (Form2.ErrorValueXEdit.Text);
If ErrorFlagY THen ValueY := StrToFloat (Form2.ErrorValueYEdit.Text);

If Form2.Combine1TypeCombo.ItemIndex = 0 THen Chart1 [Chart1.SeriesCount-WhichSeries].AddXY (ValueY, ValueX, '')
Else Chart1 [Chart1.SeriesCount-WhichSeries].AddXY (ValueX, ValueY, '');
Dec (WhichSeries);
end;
end;
end;
end;
end;

Post Reply