Show a part of a chart in another

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Thorring
Newbie
Newbie
Posts: 3
Joined: Thu Jan 08, 2009 12:00 am

Show a part of a chart in another

Post by Thorring » Thu Feb 25, 2010 10:02 am

I need to show a selected part of a chart (overview) in another chart (detailed) of a big data set up to around 17 million data points.
I would like to make something like Google does in the Google financial pages e.g. http://www.google.com/finance?&gl=us&hl ... client=fss The chart-scrollbar can be resized and scrolled through the hole data set which gives the user a pretty good overview of a quite big data set.

I have tried to user TCursorTool in the overview chart for the selection but it does not provide the right functionality as I see it. The BigFlatFile example handles the huge data set perfectly but the scrollbar cannot be resized and there is no overview-chart.

Could you give some suggestions for a solution to this problem?

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

Re: Show a part of a chart in another

Post by Yeray » Thu Feb 25, 2010 1:05 pm

Hi Thorring,

Here is a possibility using a TColorBandTool:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart2.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart2.Legend.Visible:=false;

  Series1.FillSampleValues(1000);
  Series2.DataSource:=Series1;

  Chart2.Draw;
  ChartTool1.Axis:=Chart2.Axes.Bottom;
  ChartTool1.Gradient.Visible:=True;
  ChartTool1.StartValue:=50;
  ChartTool1.EndValue:=200;
  ChartTool1.StartLine.Active:=true;
  ChartTool1.EndLine.Active:=true;

  Chart1.Axes.Bottom.SetMinMax(ChartTool1.StartValue, ChartTool1.EndValue);
end;

procedure TForm1.ChartTool1Resized(Sender: TObject);
begin
  Chart1.Axes.Bottom.SetMinMax(ChartTool1.StartValue, ChartTool1.EndValue);
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

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

Re: Show a part of a chart in another

Post by Yeray » Thu Feb 25, 2010 3:02 pm

Hi Thorring,

As an update note that you can use two independent charts, but maybe the TSubChartTool gives you a more compact result.
Here it is a picture of what you can do:
Attachments
test.png
test.png (24.98 KiB) Viewed 5365 times
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

Thorring
Newbie
Newbie
Posts: 3
Joined: Thu Jan 08, 2009 12:00 am

Re: Show a part of a chart in another

Post by Thorring » Thu Feb 25, 2010 9:03 pm

Hi Yeray,

It looks pretty cool but I still struggle with some minor problems. I am not sure about the ChartTool1Resized and where I find it? Further, I do not find the Draw property you are using but only one with parameters (canvas, Rect)? Will Repaint do it?

TSubChartTool looks cool as well, but it is not what I am looking for this time. I need to show up to 6 graphs in the chart with a lot of indications of ‘bad data areas’, spikes, rapid changes in data and so on. It will be too much to show the sub-chart in this mess of indications.

Best regards
Thorring

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

Re: Show a part of a chart in another

Post by Yeray » Fri Feb 26, 2010 9:23 am

Hi Thorring,

Here you have a more complete example with TSubChartTool. Note that the ColorBand1Resized event is called when you resize the tool in the chart in the bottom.

Code: Select all

  private
    { Private declarations }
    procedure ColorBand1Resized(Sender: TObject);
//...

uses series, TeeTools, TeeSubChart;

var SubChart1: TSubChartTool;
    ColorBand1: TColorBandTool;

procedure TForm1.FormCreate(Sender: TObject);
var Chart2: TChart;
    i: Integer;
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart1.Title.Visible:=false;
  for i:=0 to 2 do
  with Chart1.AddSeries(TAreaSeries.Create(self)) as TAreaSeries do
  begin
    FillSampleValues(1000);
    AreaLinesPen.Visible:=false;
    MultiArea:=maStacked;
    Transparency:=50;
  end;
  Chart1.MarginUnits:=muPixels;
  Chart1.MarginBottom:=100;
  Chart1.MarginLeft:=20;
  Chart1.MarginTop:=20;
  Chart1.MarginRight:=20;

  SubChart1:=Chart1.Tools.Add(TSubChartTool.Create(self)) as TSubChartTool;
  Chart2:=SubChart1.Charts.AddChart;
  Chart2.View3D:=false;
  for i:=0 to Chart1.SeriesCount-1 do
  with CloneChartSeries(Chart1[i]) do
  begin
    ParentChart:=Chart2;
    Color:=Chart1[i].Color;
  end;

  Chart1.Draw;
  SubChart1.Charts.Items[0].Left:=Chart1.MarginLeft;
  SubChart1.Charts.Items[0].Top:=Chart1.Axes.Bottom.PosAxis + 25;
  SubChart1.Charts.Items[0].Width:=Chart1.Width - Chart1.MarginRight - Chart1.MarginLeft;
  SubChart1.Charts.Items[0].Height:=Chart1.Height - SubChart1.Charts.Items[0].Top;

  ColorBand1:=Chart2.Tools.Add(TColorBandTool.Create(self)) as TColorBandTool;
  ColorBand1.Axis:=Chart2.Axes.Bottom;
  ColorBand1.StartValue:=50;
  ColorBand1.EndValue:=200;
  ColorBand1.StartLine.Active:=true;
  ColorBand1.EndLine.Active:=true;
  ColorBand1.OnResized:=ColorBand1Resized;
  ColorBand1.Transparency:=50;
  ColorBand1.Pen.Width:=2;
  ColorBand1.Pen.Color:=clBlue;

  Chart1.Axes.Bottom.SetMinMax(ColorBand1.StartValue, ColorBand1.EndValue);
end;

procedure TForm1.ColorBand1Resized(Sender: TObject);
begin
  Chart1.Axes.Bottom.SetMinMax(ColorBand1.StartValue, ColorBand1.EndValue);
end;
Attachments
test.png
test.png (27.97 KiB) Viewed 5345 times
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

Thorring
Newbie
Newbie
Posts: 3
Joined: Thu Jan 08, 2009 12:00 am

Re: Show a part of a chart in another

Post by Thorring » Tue Mar 02, 2010 2:49 pm

Hi Yeray,

Thanks a lot! - the TSubChartTool will do it.

Best Regards
Henrik Thørring

Post Reply