There are two errors in your idea:
- CurrentExtent is a read-only property. It refers to the range between the axis lines which is usually a bit wider than the range defined by the data due to the chart's Margins and series labels. The range defined by the data points is called LogicalExtent. Since the CurrentExtent is calculated from the LogicalExtent and the Margins/label sizes it cannot be modified by the user directly.
- Although LogicalExtent is a read/write property still you cannot say: Chart1.LogicalExtent.a.x := 100. The type of LogicalExtent is a TDoubleRect (in unit TACharUtils), i.e. a record of two TDoublePoints, a and b, each of them with elements x and y. Since all these are no classes and since there is no setter procedure for them you are forced to assign a complete TDoubleRect record to the chart's LogicalExtent. Something like this:
procedure TForm1.MoveChartBy(dx, dy: Double);
var
ex: TDoubleRect;
begin
ex := Chart1.LogicalExtent;
ex.a.x := ex.a.x + dx;
ex.b.x := ex.b.x + dx;
ex.a.y := ex.a.y + dy;
ex.b.y := ex.b.y + dy;
Chart1.LogicalExtent := ex;
end;
Instead of coding it yourself (which is always a good idea!) you could try a
TPanClickTool. It moves the chart to the right when the user clicks somewhere within the right margin of the chart (the margin is set by the equally named property, 4 pixels by default). Similarly with left, top, bottom sides.
Since there is no tutorial on this tool here are the steps how to use it:
- Add a TChartTools component to the chart. Link it to the "Tools" property of the chart (IMPORTANT - I always forget this)
- Double-click on the ChartTools component, click "+ Add" and select "Panning by click". This adds a TPanClickTool to the tools component.
- In the object inspector, make sure that the TPanClickTool is selected. Go to property "Shift" and check "ssLeft" - this assigns the left mouse button to activate the tool.
- Check the corresponding elements of the "LimitToExtent" property if you want to suppress moving in particular directions. For example, check "pdDown" and "pdUp" if you want to allow only horizontal movement.
- In property "Interval" you can specify the milliseconds until the next panning step is executed automatically while the mouse button is pressed. Keep it at 0 if you don't want this.