I want to use a color band to select a range of bars (values) in a stacked (vertical) bar grid.
If there is an example of this, that would be nice. (I thought implemented this last fall in a demo app but can't find the app nor the questions I asked about it).
So my first question: when the mouse is clicked (MouseDown) I need to find the closest X position between the two stacked bars to start the color band. How do I find that position?
Thank you,
Ed Dressel
Selecting a range of values
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Selecting a range of values
Hi Ed,
See the second part of the reply here where I suggest a customer to use TNearestTool.GetNearestPoint function for a similar purpose.
See the second part of the reply here where I suggest a customer to use TNearestTool.GetNearestPoint function for a similar purpose.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Advanced
- Posts: 228
- Joined: Tue Aug 28, 2007 12:00 am
- Location: Oregon, USA
Re: Selecting a range of values
If the mouse click is not on a series, the nearest point tool seems to find the nearest point via radius. I need the nearest X-index point with a given mouse click.
How can I do that?
How can I do that?
Re: Selecting a range of values
Hello Ed,
In this case you should do it on your own.
It's quite easy, you just have to loop the series values, use CalcXPos to get each value X position in pixels and store the ValueIndex of the point with a smaller distance to the given mouse X pos:
Note CalcXPos returns the left position of the bar bounds, when called with a TBarSeries. That's why I added (BarWidth div 2) to the tmpXPos.
In this case you should do it on your own.
It's quite easy, you just have to loop the series values, use CalcXPos to get each value X position in pixels and store the ValueIndex of the point with a smaller distance to the given mouse X pos:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Chart1.AddSeries(TBarSeries).FillSampleValues;
end;
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var s, v, tmpXPos, tmpDist, tmpSeriesIndex, tmpValueIndex: Integer;
procedure AssignMinDist(ASeriesIndex: Integer; AValueIndex: Integer);
begin
tmpDist:=Abs(X-tmpXPos);
tmpSeriesIndex:=s;
tmpValueIndex:=v;
end;
begin
tmpSeriesIndex:=-1;
tmpValueIndex:=-1;
tmpDist:=-1;
for s:=0 to Chart1.SeriesCount-1 do
for v:=0 to Chart1[s].Count-1 do
begin
tmpXPos:=Chart1[s].CalcXPos(v);
if Chart1[s] is TBarSeries then
tmpXPos:=tmpXPos+((Chart1[s] as TBarSeries).BarWidth div 2);
if tmpDist=-1 then
AssignMinDist(s, v)
else
if (Abs(X-tmpXPos)<tmpDist) then
AssignMinDist(s, v);
end;
Caption:='SeriesIndex: ' + IntToStr(tmpSeriesIndex) + ', ValueIndex: ' + IntToStr(tmpValueIndex);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |