Page 1 of 1
Draw axis through origin
Posted: Fri Apr 24, 2009 5:14 am
by 10048056
Hello,
I'm fairly new to the newsgroup so apologies if this has been asked before.
I have an xy graph with the y axis going from negative to positive: say -100 to + 100. The x axis goes from 0: say 0 to 100. I want the x axis to go through y=0, but can't find a property to make this happen. This is like the default with an xy scatter graph in Excel 2007.
Any help much appreciated.
Thanks, Ian
Posted: Fri Apr 24, 2009 10:08 am
by yeray
Hi Ian,
Here there is an example in ActiveX. If you find problems translating it don't hesitate to let us know.
Posted: Fri Apr 24, 2009 11:34 am
by 10048056
Hi Yeray
If you've got some delphi code that would be great. I thought there might be a property to set.
Thanks, Ian
Posted: Fri Apr 24, 2009 3:28 pm
by yeray
Hi Ian,
Here is how I would traduce that VB6 code to delphi:
Code: Select all
uses series, Types;
var usePercentages: Boolean;
procedure TForm1.FormCreate(Sender: TObject);
var series1: TLineSeries;
i: Integer;
begin
Chart1.View3D := false;
series1 := TLineSeries.Create(self);
Chart1.AddSeries(series1);
for i:=-5 to 10 do
Series1.AddXY(i, i, '', clTeeColor);
Chart1.OnAfterDraw := Chart1AfterDraw;
Chart1.MarginUnits := muPixels;
usePercentages := false;
Chart1.Draw;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var chartWidth, chartHeight, horizZeroLoc, vertZeroLoc: Integer;
horizPercentLoc, vertPercentLoc: Double;
begin
with Chart1.Axes do
begin
if usePercentages then
begin
chartWidth := Chart1.ChartRect.Right - Chart1.ChartRect.Left;
horizZeroLoc := Bottom.CalcXPosValue(0) - Chart1.ChartRect.Left;
horizPercentLoc := horizZeroLoc / chartWidth * 100;
Left.PositionUnits := muPercent;
Left.PositionPercent := horizPercentLoc;
chartHeight := Chart1.ChartRect.Bottom - Chart1.ChartRect.Top;
vertZeroLoc := Left.CalcYPosValue(0) - Chart1.ChartRect.Top;
vertPercentLoc := vertZeroLoc / chartHeight * 100;
Bottom.PositionUnits := muPercent;
Bottom.PositionPercent := 100 - vertPercentLoc;
end
else
begin
Left.PositionUnits := muPixels;
Left.PositionPercent := Bottom.CalcXPosValue(0) - Chart1.ChartRect.Left;
Bottom.PositionUnits := muPixels;
Bottom.PositionPercent := Chart1.ChartRect.Bottom - Left.CalcYPosValue(0);
end;
end;
end;
Posted: Fri Apr 24, 2009 10:53 pm
by 10048056
Hi Yeray
Once again - problem solved. Many thanks.
Bit of a delay getting back to you because of the time difference here in Australia.
Best regards,
Ian