I'm having trouble figuring out how to add TZoomDragTool to a TChart. I know that TChart has built in support for zooming, but I want to disable panning (drag with right click) at the same time. There is a property to disable zooming, but no straight forward way to disable panning.
What I found out is that if I add a TChartToolSet to the chart, it will disable both the built in zooming and panning capabilities. If I can add a TZoomDragTool to the TChartToolSet, then it will do what I want. It works well if I do it at design time, but I don't know how to do it at run time.
Appreciate it if someone could show me how to do it.
I have a small code snippet and it gives me errors if I run it.
TForm1 = class(TForm)
Button1: TButton;
m_chart: TChart;
m_toolset: TChartToolset;
m_zoom: TZoomDragTool;
procedure Button1Click(Sender: TObject);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
m_chart:= TChart.Create(self);
with m_chart do begin
autosize:= False;
left:= 10;
top:= 40;
width:= 300;
height:= 150;
parent:= Self;
visible:= True;
end;
m_toolset:= TChartToolset.Create(m_chart); //is the owner correct?
m_zoom:= TZoomDragTool.Create(m_toolset); //is the owner correct?
m_toolset.Tools.Add(@m_zoom); //is this correct?
m_chart.Toolset:= m_toolset; //is this the way?
//or something like
//m_chart.Toolset.InsertComponent(m_toolset);
//both of them crash
end;