Page 1 of 1

Controlling the Position of Stacked Bar Charts

Posted: Tue Mar 18, 2014 4:27 am
by 16566546
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

Re: Controlling the Position of Stacked Bar Charts

Posted: Tue Mar 18, 2014 3:09 pm
by yeray
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 3420 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