Here's a method of simulating a selection in the TChart Delphi control. When a user clicks on a bar of a chart, the respective bar changes its color.
Everything is being done using one event, the onClickSeries, which provides us the index of the clicked bar.
Follow the steps:
- Drop a TChart ("Additional" tab) control on a Delphi form.
- Add one (empty) series to the Chart.
- Select a "Bar" chart style.
colors : array of TColor;Fill in the Chart with some "dummy" data in the Form's OnCreate event:
k : integer;
procedure TChartForm.FormCreate(Sender: TObject) ;Handle the OnClickSeries event as:
begin
SetLength(colors,7) ;
for k := 0 to 6 do colors[k] := clBlue;
Chart1.Series[0].Add(10,'test2',Colors[0]) ;
Chart1.Series[0].Add(70,'test3',Colors[1]) ;
Chart1.Series[0].Add(90,'test4',Colors[2]) ;
Chart1.Series[0].Add(40,'test5',Colors[3]) ;
Chart1.Series[0].Add(66,'test6',Colors[4]) ;
end;
procedure TChartForm.Chart1ClickSeries(Delphi tips navigator:
Sender: TCustomChart;
Series: TChartSeries;
ValueIndex: Integer;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer) ;
begin
for k := 0 to 6 do
if k <> ValueIndex then
colors[k] := clBlue
else
colors[k] := clRed;
Chart1.Series[0].Clear;
Chart1.Series[0].Add(10,'test2',Colors[0]) ;
Chart1.Series[0].Add(70,'test3',Colors[1]) ;
Chart1.Series[0].Add(90,'test4',Colors[2]) ;
Chart1.Series[0].Add(40,'test5',Colors[3]) ;
Chart1.Series[0].Add(66,'test6',Colors[4]) ;
end;
» Register a File Command for a Windows Shell Menu from Delphi code
« Troubleshooting the "Left Side Cannot Be Assigned To" Compile Time Delphi Error


