Drawing on a Rose Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
esbglenn
Newbie
Newbie
Posts: 7
Joined: Fri Apr 04, 2014 12:00 am
Contact:

Drawing on a Rose Chart

Post by esbglenn » Tue Jun 17, 2014 8:01 am

Hi,

Is it possible to draw a "*" or some other character at a given angle and radius on a Rose Chart?

I seem to recall doing something like this many years ago (not with Rose but with a bar chart or pie chart) with TeeChart but I can't find where I did it.

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

Re: Drawing on a Rose Chart

Post by Yeray » Tue Jun 17, 2014 2:25 pm

Hello,

Here you have a simple example about how to do this.
Note I've extracted the CalcXYPosition method from TPolarSeries class. You can probably simplify this method while still fitting your needs.

Code: Select all

const
 TeePiStep:Double = Pi/180.0;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var Angle, Value: Double;
    X, Y: Integer;
    tmp, AxisXRadius, AxisYRadius: Integer;
begin
  Angle:=40;
  Value:=500;

  tmp:=Series1.CirclePen.HalfWidth;
  AxisXRadius:=Series1.XRadius-tmp;
  AxisYRadius:=Series1.YRadius-tmp;

  CalcXYPosition(Series1, Angle, Value, AxisXRadius, Series1.GetHorizAxis, X, tmp);
  CalcXYPosition(Series1, Angle, Value, AxisYRadius, Series1.GetVertAxis, tmp, Y);

  Chart1.Canvas.Font.Color:=clRed;
  Chart1.Canvas.TextOut(X, Y, '*');
end;

procedure TForm1.CalcXYPosition(const ASeries: TPolarSeries; const XValue, YValue: TChartValue;
  ARadius: Integer; Axis: TChartAxis; out X, Y: Integer);

  Function CalcLogRadius(const tmpDif:Double):Double;
  var IAxisLogSizeRange : Double;
      ILogMin           : Double;
      ILogMax           : Double;
  begin
    ILogMax:=ln(Axis.Maximum);

    if Axis.Minimum<=0 then
       ILogMin:=0
    else
       ILogMin:=ln(Axis.Minimum);

    IAxisLogSizeRange:=ARadius/(ILogMax-ILogMin);

    if Axis.Inverted then
       result:=Round((ILogMax-ln(tmpDif))*IAxisLogSizeRange)
    else
       result:=Round((ln(tmpDif)-ILogMin)*IAxisLogSizeRange);
  end;

var tmp       : Double;
    tmpDif    : Double;
    tmpAtEnd  : Boolean;
    tmpRadius : Double;
begin
  With Axis do tmp:=Maximum-Minimum;

  if Axis.Inverted then
     tmpDif:=Axis.Maximum-YValue
  else
     tmpDif:=YValue-Axis.Minimum;

  if Axis.Logarithmic then tmpAtEnd:=tmpDif<=0
                      else tmpAtEnd:=tmpDif<0;

  if (tmp=0) or tmpAtEnd then
  begin
    X:=ASeries.CircleXCenter;
    Y:=ASeries.CircleYCenter;
  end
  else
  begin
    if Axis.Logarithmic then
       tmpRadius:=CalcLogRadius(tmpDif)
    else
       tmpRadius:=tmpDif*ARadius/tmp;

    ASeries.AngleToPos(TeePiStep*XValue,tmpRadius,tmpRadius,X,Y);
  end;
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

esbglenn
Newbie
Newbie
Posts: 7
Joined: Fri Apr 04, 2014 12:00 am
Contact:

Re: Drawing on a Rose Chart

Post by esbglenn » Tue Jun 17, 2014 3:04 pm

Many thanks - worked as needed once I adjusted for my own code :)

Now to sit down and examine what actually happens. Great support!

Post Reply