Page 1 of 1

THistogramSeries Hollow line: how ho hide vertical lines

Posted: Thu Apr 16, 2009 9:59 am
by 10045676
Hello,
I am a Teechart 8 user on Delphi 7 / 2007 platform, and this is my situation:

- Normally I plot a simple vertical bar chart that represents some values during the days of a month.

- Sometimes I need to show an additional target line, this target line can vary from day to day.

- I found the Histogram "hollow" type the perfect fit to have the stairs exactly over the existing bars but it is not nice to see the first left vertical line and the last right vertical line of this serie.

- I tried other solutions like using the line series with stairs options but it starts in the middle of the values bar and I cannot find an offset for this.

- So, my question is if it is possible, programmatically, to hide the vertical lines of a THistogram (ot TBar) type bar (in my specific case I need to hide, or colour it like my background, the leftmost and rightmost vertical lines).

Thanks in Advance,
Massimo

Posted: Thu Apr 16, 2009 11:04 am
by yeray
Hi Massimo,

Have you tried this?

Code: Select all

Series1.Pen.Color := Series1.Color;

Posted: Thu Apr 16, 2009 11:36 am
by 10045676
9348257 wrote:Hi Massimo,

Have you tried this?

Code: Select all

Series1.Pen.Color := Series1.Color;
Hi Yeray,
I need to modify the color only for one side of the bar, for example something like this:

Series1.<bar left side>Pen.Color := clWhite;

Posted: Thu Apr 16, 2009 1:50 pm
by yeray
Hi Massimo,

In that case I'm afraid that you only can draw the lines directly to the canvas by yourself. Here is a simple example:

Code: Select all

uses series, TeCanvas;

var series1: TBarSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := False;
  series1 := TBarSeries.Create(nil);
  Chart1.AddSeries(series1);
  series1.FillSampleValues(10);
  series1.BarWidthPercent := 100;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var X, Y0, Y1: Integer;
begin
  with Chart1.Canvas do
  begin
    X := series1.CalcXPos(0);
    Y0 := Chart1.Axes.Left.CalcYPosValue(0);
    Y1 := series1.CalcYPos(0);

    Pen.Color := clRed;
    Line(X,Y0,X,Y1);

    X := series1.CalcXPos(series1.Count-1) + series1.BarWidth;
    Y0 := Chart1.Axes.Left.CalcYPosValue(0);
    Y1 := series1.CalcYPos(series1.Count-1);

    Pen.Color := clRed;
    Line(X,Y0,X,Y1);
  end;
end;

Posted: Thu Apr 16, 2009 3:00 pm
by 10045676
9348257 wrote: series1 := TBarSeries.Create(nil);
...
X := series1.CalcXPos(series1.Count-1) + series1.BarWidth;
Thanks Alonso,
and how to identify X in case of THistogramSeries ?
I don't have the BarWidth property in THistogramSeries...

Massimo

Posted: Fri Apr 17, 2009 8:45 am
by yeray
Hi Massimo,

Yes, with histograms you should calculate the bar width by yourself. Also note that Bar series, by default, sets left axis minimum to zero while Histogram series takes the series minimum.

So for histogram series here is the example:

Code: Select all

uses Series, TeCanvas;

var series1: THistogramSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := False;
  series1 := THistogramSeries.Create(nil);
  Chart1.AddSeries(series1);
  series1.FillSampleValues(10);
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var X, Y0, Y1, BarWidth: Integer;
begin
  BarWidth := series1.CalcXPos(1) - series1.CalcXPos(0);

  with Chart1.Canvas do
  begin
    X := series1.CalcXPos(0) - (BarWidth div 2);
    Y0 := Chart1.Axes.Left.CalcYPosValue(Chart1.Axes.Left.Minimum);
    Y1 := series1.CalcYPos(0);

    Pen.Color := clRed;
    Line(X,Y0,X,Y1);

    X := series1.CalcXPos(series1.Count-1) + (BarWidth div 2);
    Y0 := Chart1.Axes.Left.CalcYPosValue(Chart1.Axes.Left.Minimum);
    Y1 := series1.CalcYPos(series1.Count-1);

    Pen.Color := clRed;
    Line(X,Y0,X,Y1);
  end;
end;

Posted: Fri Apr 17, 2009 10:09 am
by 10045676
Thanks Alonso,
it works perfectly as my needs !

Regards
Massimo