excel vba - Calculating datapoint position with chart mouseover event -
I have an embedded chart on a sheet (X, Y scatter). I also have a mouseover event on the chart - when you hover over a DietPower - prints the selected value of the same datapout for the cell. It works with using the GETChartElement method.
However, I would like to add a feature in which you can add an arrow (or line) by adding a Deatpoint and a predefined, named cell. I was also able to do this, but Unfortunately my calculation was not enough because the line is not at all at the endpoint of the dotpoint point but anywhere near it (see picture).
>
The way I did this:
Private sub as myChartClass_MouseMove (ByVal button long, unless shift byval ByVal X long, ByVal y as long) Me.myChartClass.GetChartElement first, second, ElementID, ARG1, aRG2 set chrt = ActiveSheet.ChartObjects (1) .Chart set Service = ActiveSheet.ChartObjects (1) .Chart.SeriesCollection (1) chart_data = ser.Values chart_label = ser.XValues YValue = chart_data (aRG2) XValue = chart_label (aRG2) '[code to print corresponding values] If addcomment = true then wks35.add comment (XValue, YVal Ue) Call
In this way I can pass the actual value (XValue, YValue) to the horoscope (X, Y variable) and axes. Up, the latter is used.
Double width double as the dim chart framework in the form of a slow chart obz chart, double the width of the double lamp dim L as long as 1, L2 long, R long as 1, as long as R2 Wks35 set chartObj = .ChartObjects (1) .Chart chartWidth = chartObj.PlotArea.Width chartHeight = chartObj.PlotArea.Height Y = chartHeight - (chartHeight * ((Y - chartObj .Axes (xlValue) .MinimumScale) _ /(chartObj.Axes(xlValue).MaximumScale - chartObj.Axes (xlValue) .MinimumScale))) One C = chartWidth * ((x - chartObj.Axes (xlCategory) .MinimumScale) / _ .. (chartObj.Axes (xlCategory) .MaximumScale - chartObj.Axes (xlCategory) .MinimumScale)) L1 = Range ( "Comment1") Left l2 = range ("Comment1") top r1 = X + ActiveSheet.ChartObjects (1). Left + Chart obz.platreind LEFT R2 = Y + activate. Chart object (1). Top + Chart Oz. PlotArea Insidestop with ActivateHeat Shapes. Aadine (L1, L2, R1, R2). Line .phone converter RGB = RGB (255, 0, 0) ending with the end of the term sub
was originally considered, considering the minimum and maximum values on axis and axis on its axis Calculating the relative position gives full top and left value of the dotpoint point from Plotarea boundaries. Then add the difference of the chart and plotrea and then the chart top and left.
It can be long and difficult, but I appreciate any help.
chartWidth = chart_bj PlotArea.InsideWidth chartHeight = chartObj.PlotArea.InsideHeight
/ p>
chartWidth = chartObj.PlotArea.Width chartHeight = chartObj.PlotArea.Height
it almost was there so I added some constants in the end (10 left , 3 above) lines are in their place.
Comments
Post a Comment