简体   繁体   中英

Delphi: Bind a Chart with a DBGrid

I want to bind a Chart with a DBGrid. Refer to the exhibit. When I click in the DBGrid on number 3 (X-Axis), then the bar at position three should be highlighted(or a pointer to bar 3). When I click on number 4 in the Grid then bar 4 is highlighted etc. I'm using a TDBChart

Is there a way to do this?

样本图图像

Not knowing what the charting component is, cannot provide a working example, but the key which you are looking for is to use the AfterScroll event for the dataset in the grid. Since each row represents a different record, that event is fired when the grid selection moves to the row.

Edit: This doesn't highlight with a box, but does change the color of the value marks at the top of each bar. Hopefully this gets you on your way. MyQuery is what is feeding the datasource

var 
  savecolor : tcolor;

procedure MyForm.FormShow(Sender:TObject);
begin
 ...
 SaveColor := dbchart1.series[0].marks.items[0].color;
 ...
end;

procedure MyForm.MyQueryBeforeScroll(DataSet : TDataSet);
begin
  dbchart1.series[0].marks.items[MyQuery.recno-1].color := SaveColor;
end;

procedure MyForm.MyQueryAfterScroll(DataSet:TDataSet);
begin
 dbchart1.series[0].marks.items[MyQuery.recno-1].color := clRed;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM