Three coordinate systems are involved when drawing a chart on the screen:
- The inner-most coordinates are the pixels on the screen, TAChart calls them image coordinates.
- The outer-most coordinates are the values plotted on the axes; these are the units of the data values provided by the chart source. In TAChart speak these are called axis coordinates.
- In between these two systems are the graph coordinates. This is an inivisible linear coordinate system layed over the chart. The connection between graph and image coordinates is made by the chart methods GraphToImage and ImageToGraph. The connection between graph and axis coordinates is defined by axis transformations. The axis transformations provide methods GraphToAxis and AxisToGraph. Normally, where there is no transformation, TAChart uses an identity transformation, i.e. assumes graph and axis coorindates to be equal. When the transformations object has been assigned to an axis you can also call the axis' GraphToAxis and AxisToGraph methods. And when a series has been assigned to an axis (by setting its AxisIndexX and/or AxisIndexY) you can also use the series' methods GraphToAxis and AxisToGraph.
Suppose you have a chart with two y axes, the right one displaying values between 0 and 100, and you want to determine the y pixel coordinates of some y axis value, say 27. Knowing the axis coordinates (27) you must determine the graph coordinate. Since the right axis is subject to an axis transformation you can call
Chart.AxisList[2].GetTransform in order to dermine the TAChartTransformations applicable to this axis; this also takes care of the identity transform when no external transformations object is used. Then call the transformations method AxisToGraph to get the graph y value. Finally apply Chart.YGraphToImage to determine the pixel value:
uses
TAChartAxis, TATransformations;
function YAxisToPixels(AChart: TChart; AxisIndex: Integer; y: Double): Integer;
var
axis: TChartAxis;
grY: Double;
begin
axis := AChart.AxisList[AxisIndex];
grY := axis.GetTransform.AxisToGraph(Y);
Result := AChart.YGraphToImage(grY);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(YAxisToPixels(Chart1, 1, 0.2).ToString);
end;
If this general information does not help you enough to solve the issue you should create a small demo project showing the issue. Pack ,pas, .lfm, lpr, .lpi files to a common zip which you can upload under "Attachments and other options".