Elementary(?) GetChartElement Question

  • Thread starter Thread starter MikeM
  • Start date Start date
M

MikeM

I plot a time series and want to record the specific date of a point. Using
the mouse and GetChartElement, I select the point, determine that the
ElementID is 3 and that I have selected the correct SeriesIndex. However,
PointIndex, the fifth argument in GetChartElement, returns as -1, showing
that the entire series has been selected. How can I determine the point
number?

TIA,
Mike
 
MouseDown: Each point represents a month (Jan 1960 is the first month).

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift As
Long, ByVal x As Long, ByVal Y As Long)
Dim kMo As Long, kYr As Long, iPt As Long
ActiveChart.GetChartElement x, Y, kMo, kYr, iPt
If kMo = 3 Then
kMo = (iPt - 1) Mod 12 + 1
kYr = Int((iPt - 0.9) / 12) + 1960
Sheets("Sheet1").CheckDate (kMo & "/" & kYr)
End If
End Sub
 
I can't break it in 2007 SP2 or 2003 SP3 in three ways: on a chart sheet
with the code behind the sheet, on a chart sheet using a class module,
or on an embedded chart using a class module. I have in the past found
irregularities with MouseUp and MouseDown, but not in this simple exercise.

As a programming note, you really ought to use the built-in argument
names when calling a function like GetChartElement, and don't try to
save a byte or two by using the same variable for one of these arguments
and for a calculated value. It makes it hard for someone else (me) to
figure out what you're doing, and it makes it hard to debug. Suppose for
example the code stops at the CheckDate line; how do you know the values
of Arg1 and Arg2?

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift _
As Long, ByVal x As Long, ByVal Y As Long)
Dim kMo As Long, kYr As Long, iPt As Long
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
ActiveChart.GetChartElement x, Y, ElementID, Arg1, Arg2
If ElementID = 3 Then
kMo = (Arg2 - 1) Mod 12 + 1
kYr = Int((Arg2 - 0.9) / 12) + 1960
'Sheets("Sheet1").CheckDate (kMo & "/" & kYr)
End If
End Sub

- Jon
 
I tried your code, but there was no change.

The program was working fine, as originally written, when the data was
plotted as xyscattergrams. However, when I converted them to area plots,
that's when the problem popped up. [I should have mentioned this earlier :-(
, but I thought that this was (or should be) irrelevant. Apparently it isn't.]
 
Mike -

That bit of information (chart type) would have been helpful. An area
chart doesn't have discrete points to click on, though you can mouse
over the general vicinity of where a marker would go and get the chart tip.

If you *need* the fill of an area chart, you could plot the area chart,
then overlay it with line chart series with the same data. Then bail out
of the event procedure if Arg2 < 0.

(I didn't say the code I supplied would work any better, just that it
would make your life easier.)

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


I tried your code, but there was no change.

The program was working fine, as originally written, when the data was
plotted as xyscattergrams. However, when I converted them to area plots,
that's when the problem popped up. [I should have mentioned this earlier :-(
, but I thought that this was (or should be) irrelevant. Apparently it isn't.]

Jon Peltier said:
I can't break it in 2007 SP2 or 2003 SP3 in three ways: on a chart sheet
with the code behind the sheet, on a chart sheet using a class module,
or on an embedded chart using a class module. I have in the past found
irregularities with MouseUp and MouseDown, but not in this simple exercise.

As a programming note, you really ought to use the built-in argument
names when calling a function like GetChartElement, and don't try to
save a byte or two by using the same variable for one of these arguments
and for a calculated value. It makes it hard for someone else (me) to
figure out what you're doing, and it makes it hard to debug. Suppose for
example the code stops at the CheckDate line; how do you know the values
of Arg1 and Arg2?

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift _
As Long, ByVal x As Long, ByVal Y As Long)
Dim kMo As Long, kYr As Long, iPt As Long
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
ActiveChart.GetChartElement x, Y, ElementID, Arg1, Arg2
If ElementID = 3 Then
kMo = (Arg2 - 1) Mod 12 + 1
kYr = Int((Arg2 - 0.9) / 12) + 1960
'Sheets("Sheet1").CheckDate (kMo & "/" & kYr)
End If
End Sub

- Jon
 
Thanks, Jon. I didn't realize that the sub didn't work for area plots. I've
reconfigured the plot so that there is only one filled-in (area) time series,
and the points from other time series can be selected.

Jon Peltier said:
Mike -

That bit of information (chart type) would have been helpful. An area
chart doesn't have discrete points to click on, though you can mouse
over the general vicinity of where a marker would go and get the chart tip.

If you *need* the fill of an area chart, you could plot the area chart,
then overlay it with line chart series with the same data. Then bail out
of the event procedure if Arg2 < 0.

(I didn't say the code I supplied would work any better, just that it
would make your life easier.)

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


I tried your code, but there was no change.

The program was working fine, as originally written, when the data was
plotted as xyscattergrams. However, when I converted them to area plots,
that's when the problem popped up. [I should have mentioned this earlier :-(
, but I thought that this was (or should be) irrelevant. Apparently it isn't.]

Jon Peltier said:
I can't break it in 2007 SP2 or 2003 SP3 in three ways: on a chart sheet
with the code behind the sheet, on a chart sheet using a class module,
or on an embedded chart using a class module. I have in the past found
irregularities with MouseUp and MouseDown, but not in this simple exercise.

As a programming note, you really ought to use the built-in argument
names when calling a function like GetChartElement, and don't try to
save a byte or two by using the same variable for one of these arguments
and for a calculated value. It makes it hard for someone else (me) to
figure out what you're doing, and it makes it hard to debug. Suppose for
example the code stops at the CheckDate line; how do you know the values
of Arg1 and Arg2?

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift _
As Long, ByVal x As Long, ByVal Y As Long)
Dim kMo As Long, kYr As Long, iPt As Long
Dim ElementID As Long, Arg1 As Long, Arg2 As Long
ActiveChart.GetChartElement x, Y, ElementID, Arg1, Arg2
If ElementID = 3 Then
kMo = (Arg2 - 1) Mod 12 + 1
kYr = Int((Arg2 - 0.9) / 12) + 1960
'Sheets("Sheet1").CheckDate (kMo & "/" & kYr)
End If
End Sub

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/



MikeM wrote:
MouseDown: Each point represents a month (Jan 1960 is the first month).

Private Sub myChartClass_MouseDown(ByVal Button As Long, ByVal Shift As
Long, ByVal x As Long, ByVal Y As Long)
Dim kMo As Long, kYr As Long, iPt As Long
ActiveChart.GetChartElement x, Y, kMo, kYr, iPt
If kMo = 3 Then
kMo = (iPt - 1) Mod 12 + 1
kYr = Int((iPt - 0.9) / 12) + 1960
Sheets("Sheet1").CheckDate (kMo & "/" & kYr)
End If
End Sub

:

What event are you trapping to get X and Y?

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/



MikeM wrote:
I plot a time series and want to record the specific date of a point. Using
the mouse and GetChartElement, I select the point, determine that the
ElementID is 3 and that I have selected the correct SeriesIndex. However,
PointIndex, the fifth argument in GetChartElement, returns as -1, showing
that the entire series has been selected. How can I determine the point
number?

TIA,
Mike
 
Back
Top