Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Plot accurate point on the Excel Chart through mouse click

Status
Not open for further replies.

jet737

Programmer
Jan 24, 2002
6
IN
I am sending the code which plots the point on the but not in the accurate way.Can anybody help

Private Sub Chart1_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Static col As Integer
Dim iVal As Integer
If isNewpoint Then
'Chart function for determining the area clicked.
'GetChartElement function determines the various chart elements
Call Chart1.GetChartElement(x, y, m_ElemId, m_Arg1, m_Arg2)
Select Case m_ElemId
Case xlPlotArea, xlMajorGridlines, xlMinorGridlines
iVal = arrVal + 1
If col >= 256 Then
col = 0
End If
col = col + 1
ar = 4 / 3
xrng = ActiveChart.Axes(xlCategory).MaximumScale
adjx = x - ar * (ActiveChart.PlotArea.InsideLeft + ActiveChart.ChartArea.Left)
effwdth = ar * ActiveChart.PlotArea.InsideWidth
xscf = xrng / effwdth
tos = ActiveChart.ChartArea.Top + ActiveChart.PlotArea.InsideTop
adjy = ar * (ActiveChart.PlotArea.InsideHeight + tos) - y
yrng = ActiveChart.Axes(xlValue).MaximumScale
effht = ar * ActiveChart.PlotArea.InsideHeight
yscf = yrng / effht
Yval = Int(adjy * yscf)
ReDim Preserve arrXval(iVal) As Integer
ReDim Preserve arrYval(iVal) As Integer
ReDim Preserve arrXcor(iVal) As Long
ReDim Preserve arrYcor(iVal) As Long
getpos
arrXval(iVal) = Int(adjx * xscf)
arrYval(iVal) = Yval
arrXcor(iVal) = x
arrYcor(iVal) = y
arrVal = iVal
ActiveSheet.Range(AlphaCh + "1").Value = Int(adjx * xscf)
ActiveSheet.Range(AlphaCh + "2").Value = Yval
Case xlSeries
SeriesId = m_Arg1
PointId = m_Arg2
ShowPointValue
End Select
Sheet1.CmdNewPoint.Enabled = False
isNewpoint = False
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top