Line and Area Series


Q: Automatic Axes do not scale well with big line pen widths.

"A few months now, we're using the TeeChart component in Delphi3 with success. One little misbehaviour took our attention : when using the automatic scaling-option for X & Y axes, we saw that we can't see the max-values drawn in our chart on top or bottom
(they are really there : you can see them when you drag the whole chart down)."

You can expand the axis with the code below.

"I was thinking to add a new property to the Series to solve this problem. Something like Series1.MarginTop:=5 to leave 5 pixels on top of the blue line. Another thing I can do is to make the TLineSeries and TFastLineSeries more smart, to display completely depending on the LinePen Width. I'll add this to the to-do list." (David Berneda)

DELPHI CODE : 

With Chart1.LeftAxis do Maximum:=Maximum+Maximum*1.0/100.0;

CBUILDER CODE : 

Chart1->LeftAxis->Maximum=
Chart1->LeftAxis->Maximum+Chart1->LeftAxis->Maximum*0.01; 

Q: How can I plot a circle using a Line Series ?


By default, most Series like Line Series order points using their X coordinate. If you don't supply the X coordinate (by calling AddXY or setting the X field in a DBChart), the X coordinate will be the order in which points are added to the series.

To draw a circle, you should first disable this automatic ordering, so the Series will draw points in the order you added them to the Series.

DELPHI CODE : 

Var t:Integer;
begin
  Series1.XValues.Order:=loNone ;
  for t:=0 to 360 do Series1.AddXY( Sin(t*Pi/180.0), 
Cos(t*Pi/180.0), '', clRed );
end;

CBUILDER CODE : 

Series1->XValues->Order=loNone;
for (int t=0;t<=360;t++)
  Series1->AddXY( sin(t*3.14/180.0),
                  cos(t*3.14/180.0), "", clRed );

Q: I am trying to set the line style (Dotted, Dashed etc) for a Line Series at runtime in my code but cannot seem to get it right.


Set the LinePen Style property.

DELPHI CODE : 

Series1.LinePen.Style:=psDot;

CBUILDER CODE : 

Series1.LinePen.Style=psDot;

Q: Is there a simple way I can plot X-Y graph?


Set the LinePen Visible property.

DELPHI CODE : 

Series1.LinePen.Visible:=False;

CBUILDER CODE : 

Series1->LinePen->Visible=false;

or use the TPoint series and AddXY method.


Q: I use Chart.Series[0].Pointer.Visilble:=false It fails. How can I set points not visible at run-time?


Chart1.Series[0].Pointer.Visible:=false; will fail. You have to use the following:

DELPHI CODE : 

(Chart1.Series[0] as TLineSeries).Pointer.Visible:=false;

CBUILDER CODE : 

if (dynamic_cast<TLineSeries*>(Chart1->Series[0]))
 dynamic_cast<TLineSeries*>(Chart1->Series[0])->Pointer->Visible=false;

Q: With a diagonal hatching and the area lines set to invisible the diagonal lines are not continuous - but are broken where the data point are despite having the area lines set to invisible on the series. Is there anyway of overcoming this?

This one can be handled with :

DELPHI CODE : 

Series1.AreaLinesPen.Visible:=true;
Series1.AreaLinesPen.Style:=psClear;

CBUILDER CODE : 

Series1->AreaLinesPen->Visible=true;
Series1->AreaLinesPen->Style=psClear;

Q: Is there a way for a TLineSeries series to not start and end at the left and right axis?

The TLineSeries.Pointer offers InflateMargins property. When set to true, the pointer horizontal and vertical size are taken into the account when axis min-max value is calculated. But if you don't want to display pointers, then you can :

1) Use TChartAxis SetMinMax method and set axis minimum and maximum value to [real_min-offset,real_max+offset]. The drawback is axis is not automatic anymore.

2) Use the simple trick : create a fake TPointSeries. Don't display it (by setting SeriesColor=clNone). Assign Series1 (original series displayed) values to fakeSeries. When the axis min-max value is calculated, the fakeSeries Pointer VertSize and HorizSize are taken into the account ==> you get offset:

DELPHI CODE : 

var fakeSeries:TPointSeries;

begin
  Series1.FillSampleValues(20); // original series
  // fake series
 fakeSeries:=TPointSeries.Create(self);
 fakeSeries.AssignValues(Series1); // get values from original series
 fakeSeries.Pointer.HorizSize:=5; // 5 pixels horizontal offest
 fakeSeries.Pointer.VertSize:=2; // 2 pixels vertical offset
 fakeSeries.Pointer.InflateMargins:=true; // must be true
 fakeSeries.ShowInLegend:=false; // we don't want it in legend
 fakeSeries.SeriesColor:=clNone; // nothing to see :)
 fakeSeries.ParentChart:=Series1.ParentChart;

CBUILDER CODE : 

 Series1->FillSampleValues(20); // original series
  // fake series
 TPointSeries *fakeSeries=new TPointSeries(this);
 fakeSeries->AssignValues(Series1); // get values from original series
 fakeSeries->Pointer->HorizSize=5; // 5 pixels horizontal offest
 fakeSeries->Pointer->VertSize=2; // 2 pixels vertical offset
 fakeSeries->Pointer->InflateMargins=true; // must be true
 fakeSeries->ShowInLegend=false; // we don't want it in legend
 fakeSeries->SeriesColor=clNone; // nothing to see :)
 fakeSeries->ParentChart=Series1->ParentChart;

Q: Can I force the order how points are joined together in fastline series, avoiding ascending order as it is by default?


For example points (x,y):   A(1,4), C(5,4), B(2,3)  will be joined ABC, I need  line to be draw ACB

Yes. By default, the order is "ascending" on X values (horizontal).


To disable:

VCL version: Series1.XValues.Order:=loNone ;

ActiveX version: Chart1.Series(0).XValues.Order = loNone

All points added after the above instruction will not be sorted.