Controlling the Position of Stacked Bar Charts

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Errol
Newbie
Newbie
Posts: 75
Joined: Thu Jul 11, 2013 12:00 am

Controlling the Position of Stacked Bar Charts

Post by Errol » Tue Mar 18, 2014 4:27 am

Is there currently any method of controlling the horizontal position of stacked bar charts? For instance, if a scientist were to measure a number of parameters at irregular time intervals, and wanted to display each set of parameters using a stacked bar chart, with the x-axis representing the time axis. This is a common requirement, and displaying this data at equal intervals does not accurately express the true data trends with time.

I look forward to any suggestions you may have.

Best regards

Errol

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

Re: Controlling the Position of Stacked Bar Charts

Post by Yeray » Tue Mar 18, 2014 3:09 pm

Hello Errol,

With mbStacked MultiBar style it's straightforward. You add the values to your series with XValue and the values of the different series in the same XValue will be stacked. Ie:

Code: Select all

uses Series, DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
    tmpDates: array of TDateTime;
begin
  Chart1.View3D:=false;

  setLength(tmpDates, 5);
  for i:=0 to High(tmpDates) do
    if i mod 2 = 0 then
      tmpDates[i]:=IncDay(Today, i*2)
    else
      tmpDates[i]:=IncDay(Today, (i*2)+1);

  for i:=0 to 4 do
  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    MultiBar:=mbStacked;
    MarksOnBar:=true;
    MarksLocation:=mlCenter;
    CustomBarWidth:=40;

    XValues.DateTime:=true;
    for j:=0 to High(tmpDates) do
      AddXY(tmpDates[j], 25+random*75, 'S' + inttoStr(i) + ' L' + IntToStr(j));
  end;

  Chart1.Legend.Alignment:=laBottom;
  Chart1.Axes.Bottom.LabelStyle:=talPointValue;
  Chart1.Axes.Bottom.LabelsAngle:=90;
end;
mbStacked.png
mbStacked.png (25.15 KiB) Viewed 3390 times
With mbSelfStack I'm afraid this can't be done because this MultiBar style doesn't use the XValues in the series to draw the bars; the x positions in the horizontal axis are just sequential. I'll add to the wish list the possibility to choose the XValue for the mbSelfStack MultiBar style to be drawn:
http://bugs.teechart.net/show_bug.cgi?id=646
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