Page 1 of 1

Polar axis labels just duplicate LeftAxis

Posted: Tue May 26, 2009 11:25 am
by 10548334
Hi,

I'm having a problem plotting PolarSeries that use separate axes. I'd like things to work the same way as linear plots, where I can assign one LineSeries to the LeftAxis and a second one to the RightAxis (or even a custom axis) and display two different quantities at once, on different scales.

Here's an illustration of what happens when I try it. In the chart below, I've enabled the left and right axes (in the polar chart, left displays as the lower axis, and right as the uppper one). I created two polar series - Series1 (the blue one) and Series2 (orange) - and set Series1's vertical axis to aLeftAxis, and Series2's to aRightAxis. I manually set the left axis to minimum 0, maximum 1000, and the right axis to min 0, max 2000. Then I set Series2's data source to Series1.

So, I should expect Series2 to be a half-size copy of Series1 (which it is) but with the upper ('right') axis running from 0-2000 and showing that the values are the same as in Series1. Instead, the scale is just a copy of the left axis, and displays 0-1000. What is wrong with the right axis labels?

Image

I'm running Windows XP SP3, RAD Studio 2007 and TeeChart 8.04.

Posted: Tue May 26, 2009 1:16 pm
by yeray
Hi Nick,

I'm afraid that Polar series wasn't thought to allow this and it's not possible to assign more than one custom axis to series' vertical axes (or vertical). I've added the request to the wish list (TV52014183).

Posted: Tue May 26, 2009 2:12 pm
by 10548334
Thanks Yeray,

It looks like it's just the axis labels that would need changing to make it work. The axes are, in other respects, independent - e.g. they can have different titles, and series assigned to them scale properly as the axis range is changed, etc. It's just the labels that read the same as the LeftAxis.

Just to be clear, I didn't particularly need to assign the same series to more than one axis. I just wanted to assign different series to different 'vertical' axes, same as I can on a linear chart. I only used series from the same data source in my post because it illustrated the point (that the second series was being plotted, correctly, as a small version of the original, but the labels were incorrect).

If you can think of something that might give me a work-around, let me know and I'll be happy to investigate the details myself (maybe something with the OnDrawLabel event?).

Posted: Tue May 26, 2009 2:45 pm
by yeray
Hi Nick,

Yes, if you only want to change Axis labels, you could do something as follows:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var Relation: Double;
begin
  if Sender = Chart1.Axes.Right then
  begin
    Relation := 2;
    LabelText := FloatToStr(StrToFloat(LabelText) / Relation);
  end;
end;

Posted: Wed May 27, 2009 1:16 pm
by 10548334
Thanks Yeray. I've done something a bit like that, but generalised it so it works whatever the difference in scales between right and left axes are.

I notice that, when OnGetAxisLabel is triggered by the RightAxis, its Minimum and Maximum get set to the same values as the LeftAxis, even though they seem to have the 'correct' values at all other times (odd behaviour..). So I added a couple of properties to my form:

Code: Select all

    RightScaling, RightOffset: Double;
and set them before it draws the axes:

Code: Select all

procedure TMainForm.Chart1BeforeDrawAxes(Sender: TObject);
begin
  with (Sender as TChart) do
  begin
    RightScaling := (RightAxis.Maximum - RightAxis.Minimum) / (LeftAxis.Maximum - LeftAxis.Minimum);
    RightOffset := RightAxis.Minimum - LeftAxis.Minimum;
  end;
end;
then change the labels like you did:

Code: Select all

procedure TMainForm.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  if (Sender = Sender.ParentChart.RightAxis) then
    LabelText := FloatToStr(StrToFloat(LabelText) * RightScaling + RightOffset);
end;
(although there's a bit of error handling and formatting in the version I use) and that works well enough for my purposes. It makes the labels at the same places as the LeftAxis, even if they're not nice round numbers on the RightAxis scale, but I can live with that.

Thanks for your help.

Posted: Wed May 27, 2009 2:09 pm
by yeray
Hi Nick,

Another possibility I can think would be to clear all the labels of this axis and add the labels you want as custom labels. Bu then you'll have to calculate how many to add and where.