Creating a Bar Chart limited to a Single Record

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
DataInspector
Newbie
Newbie
Posts: 5
Joined: Mon Sep 09, 2019 12:00 am

Creating a Bar Chart limited to a Single Record

Post by DataInspector » Wed Jul 29, 2020 8:32 pm

How can I limit a stacked bar chart to a single record from a query? I need to be able to have the chart appear to the user in a ReportBuilder Report based on current record. I have done this for 15 years or so in FastReports, but need to move beyond them for other reasons.

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

Re: Creating a Bar Chart limited to a Single Record

Post by Yeray » Thu Jul 30, 2020 8:44 am

Hello,

The easiest way I can think to do this is by setting the bottom axis to just show the last value. Ie:

Code: Select all

  with Chart1[0] do
  begin
    diff:=(XValues.Last-XValues[Count-2]) / 2;
    Chart1.Axes.Bottom.SetMinMax(XValues.Last-diff, XValues.Last+diff);
  end;
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

DataInspector
Newbie
Newbie
Posts: 5
Joined: Mon Sep 09, 2019 12:00 am

Re: Creating a Bar Chart limited to a Single Record

Post by DataInspector » Thu Jul 30, 2020 12:47 pm

Maybe I need to provide more detail. I have a series of records in a table that has three values I want to place in a stacked bar chart - Total Budget, Current Invoice, and Previous Invoices. As the report generator steps through the table, it needs to provide a chart based on the three fields in that particular record. Right now the bar chart provides separate stacked bars for the entire table all at once.

DataInspector
Newbie
Newbie
Posts: 5
Joined: Mon Sep 09, 2019 12:00 am

Re: Creating a Bar Chart limited to a Single Record

Post by DataInspector » Thu Jul 30, 2020 6:48 pm

I solved the problem by setting up a FDMemTable to provide data to the chart. As my Query steps through it's data, it triggers an OnDataChange event. I use this event to empty the MemTable and then copy the values I need from the Query to the MemTable. It works perfectly.

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

Re: Creating a Bar Chart limited to a Single Record

Post by Yeray » Fri Jul 31, 2020 6:24 am

Hello,

I may be missing something else because I still think the same code applies here.
Here a simple example showing three stacked bars with several values:

Code: Select all

var
  i: Integer;
const
  titles: array[0..2] of string = ('Total Budget', 'Current Invoice', 'Previous Invoices');
begin
  for i:=0 to 2 do
  begin
    with TBarSeries(Chart1.AddSeries(TBarSeries)) do
    begin
      Title:=titles[i];
      FillSampleValues;
      MultiBar:=mbStacked;
      Marks.Hide;
    end;
  end;

  Chart1.Legend.Alignment:=laBottom;
all.png
all.png (7.41 KiB) Viewed 13376 times
Here the same chart after calling that code to only show the last bar:
last.png
last.png (8.66 KiB) Viewed 13376 times
If you still find problems with it, please arrange a simple example project we can run as-is to reproduce the problem here.
Thanks in advance.
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