Stacked Bar Chart with Dynamic number of groups
Stacked Bar Chart with Dynamic number of groups
Using TeeChart 7 and Delphi 7:
I need to create a stacked bar chart (hopefully horizontal) with 2 bars but an dynamic number of items in each bar.
It is my understanding that the fixed number of bars are not the series but each item is a series. Therefore, I will need to dynamically create series.
I know it is possible, but I realize I may have to index them in an array or something like that -- since I will not always know the number. This seems do-able but difficult.
It would be easier if I could use the 2 groups as series. Is this possible?
thanks --
I need to create a stacked bar chart (hopefully horizontal) with 2 bars but an dynamic number of items in each bar.
It is my understanding that the fixed number of bars are not the series but each item is a series. Therefore, I will need to dynamically create series.
I know it is possible, but I realize I may have to index them in an array or something like that -- since I will not always know the number. This seems do-able but difficult.
It would be easier if I could use the 2 groups as series. Is this possible?
thanks --
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi jz8,
I may not understand what you are looking for correctly. However my suggestion would be using 2 Bar/HorizBar series and set them to mbSelfStack:
So that you can dynamically add as many values you wish to each series.
If that's not what you are trying to achieve please give us some more details. An example image would be helpful. You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
I may not understand what you are looking for correctly. However my suggestion would be using 2 Bar/HorizBar series and set them to mbSelfStack:
Code: Select all
Series1.MultiBar:=mbSelfStack;
If that's not what you are trying to achieve please give us some more details. An example image would be helpful. You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi jz8,
Thanks for the file.
Yes, using 2 THorizBarSeries and setting them to mbSelfStack would avoid having to dynamically create series. You'll find a self stack example at All Features\Welcome!\Chart Styles\Standard\Bar\Self Stacked in the new features demo, available at TeeChart's program group.
Anyway, if you need to dynamically create and remove series and have problems with this don't hesitate to let us know.
Thanks for the file.
Yes, using 2 THorizBarSeries and setting them to mbSelfStack would avoid having to dynamically create series. You'll find a self stack example at All Features\Welcome!\Chart Styles\Standard\Bar\Self Stacked in the new features demo, available at TeeChart's program group.
Anyway, if you need to dynamically create and remove series and have problems with this don't hesitate to let us know.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hello,
I see my original idea doesn't work to achieve what you request. In that case I'd do something like this:
I see my original idea doesn't work to achieve what you request. In that case I'd do something like this:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
var tmpSeries: THorizBarSeries;
i: Integer;
begin
for i:=0 to 5 do
begin
tmpSeries:=THorizBarSeries.Create(self);
Chart1.AddSeries(tmpSeries);
tmpSeries.MultiBar:=mbStacked;
tmpSeries.Marks.Style:=smsValue;
tmpSeries.AddBar(random, 'Winter', clTeeColor);
tmpSeries.AddBar(random, 'Summer', clTeeColor);
tmpSeries.Title:='My item #' + IntToStr(i+1);
end;
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 |
Instructions - How to post in this forum |
Thanks: It seems to work with the dynamic number of series.
However one additional problem, the user may change the data requiring a redrawing of the graph. Not knowing exactly what has changed I have to clear the graph and redo. I am testing this in your code with the following Button1Click procedure.
I am trying the following code (and have failed at some other attempts also), but it does not clear the series. For example, the second pass through the data I get 12 series -- not 6.
Any thoughts on how to fix this.
However one additional problem, the user may change the data requiring a redrawing of the graph. Not knowing exactly what has changed I have to clear the graph and redo. I am testing this in your code with the following Button1Click procedure.
I am trying the following code (and have failed at some other attempts also), but it does not clear the series. For example, the second pass through the data I get 12 series -- not 6.
Any thoughts on how to fix this.
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var tmpSeries: THorizBarSeries;
i, iSrs, iCnt: Integer;
begin
iCnt := Chart1.SeriesCount;
if iCnt > 0 then //if there are series, then delete
for iSrs := iCnt-1 to 0 do
Chart1.Series[iSrs].Delete(iSrs);
for i:=0 to 5 do
begin
tmpSeries:=THorizBarSeries.Create(self);
Chart1.AddSeries(tmpSeries);
tmpSeries.MultiBar:=mbStacked;
tmpSeries.Marks.Style:=smsValue;
tmpSeries.AddBar(random, 'Winter', clTeeColor);
tmpSeries.AddBar(random, 'Summer', clTeeColor);
tmpSeries.Title:='My item #' + IntToStr(i+1);
end;
label1.Caption := inttostr(chart1.SeriesCount);
end;
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi jz8,
Yes, there are a couple mistakes in the way you tried to remove series:
1. For loop should use downto keyword instead of to.
2. Using Chart1.Series[iSrs].Delete(iSrs) you are only removing the point indexed iSrs from Chart1.Series[iSrs] series.
So your code should be like this:
Or even easier:
Yes, there are a couple mistakes in the way you tried to remove series:
1. For loop should use downto keyword instead of to.
2. Using Chart1.Series[iSrs].Delete(iSrs) you are only removing the point indexed iSrs from Chart1.Series[iSrs] series.
So your code should be like this:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
AddSeries;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i, iSrs, iCnt: Integer;
begin
iCnt := Chart1.SeriesCount;
if iCnt > 0 then //if there are series, then delete
for iSrs := iCnt-1 downto 0 do
Chart1.RemoveSeries(iSrs);
AddSeries;
Label1.Caption := inttostr(chart1.SeriesCount);
end;
procedure TForm1.AddSeries;
var tmpSeries: THorizBarSeries;
i: Integer;
begin
for i:=0 to 5 do
begin
tmpSeries:=THorizBarSeries.Create(self);
Chart1.AddSeries(tmpSeries);
tmpSeries.MultiBar:=mbStacked;
tmpSeries.Marks.Style:=smsValue;
tmpSeries.AddBar(random, 'Winter', clTeeColor);
tmpSeries.AddBar(random, 'Summer', clTeeColor);
tmpSeries.Title:='My item #' + IntToStr(i+1);
end;
end;
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
AddSeries;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddSeries;
end;
procedure TForm1.AddSeries;
var tmpSeries: THorizBarSeries;
i: Integer;
begin
Chart1.RemoveAllSeries;
for i:=0 to 5 do
begin
tmpSeries:=THorizBarSeries.Create(self);
Chart1.AddSeries(tmpSeries);
tmpSeries.MultiBar:=mbStacked;
tmpSeries.Marks.Style:=smsValue;
tmpSeries.AddBar(random, 'Winter', clTeeColor);
tmpSeries.AddBar(random, 'Summer', clTeeColor);
tmpSeries.Title:='My item #' + IntToStr(i+1);
end;
Label1.Caption := inttostr(chart1.SeriesCount);
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 |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi jz8,
Not that I can think of. Which exact TeeChart version are you using?
Thanks in advance.
Not that I can think of. Which exact TeeChart version are you using?
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi jz8,
Thanks for the information.
Thinking a little bit more about that, when using RemoveAllSeries, series are not disposed. Only their ParentChart is set to null and series are removed from the series list but does not free any memory associated with them. FreeAllSeries destroys all series and frees their associated memory.
You may want to try using FreeAllSeries instead.
Thanks for the information.
Thinking a little bit more about that, when using RemoveAllSeries, series are not disposed. Only their ParentChart is set to null and series are removed from the series list but does not free any memory associated with them. FreeAllSeries destroys all series and frees their associated memory.
You may want to try using FreeAllSeries instead.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |