Reputation: 33
I am attempting to modify the tooltips of a scatter plot using Visual Basic code so that the name of the data points are in the tooltips when you click on individual data points, along with the x and y data from the plot.
I have already attempted to use:
ThisWorkbook.Worksheets("Scatter Plot").ChartObjects(1).Chart.SetSourceData Source:=ThisWorkbook.Worksheets("Sheet1").Range(col1 & ", " & col2), PlotBy:=xlColumns
ThisWorkbook.Worksheets("Scatter Plot").ChartObjects(1).Chart.SeriesCollection(1).XValues = ThisWorkbook.Worksheets("Sheet1").Range(col3)
But when I try to use it, the macro overwrites the X-value data already stored in the data points in order to add the names to the scatter plot tooltips. Is there any way that I can modify the names of the scatter plot points without modifying their x-values or using Add-Ins?
Upvotes: 1
Views: 1196
Reputation: 1013
The following code sets the Data Label (Data Callout) to the values provided in the Range "Sheet1!$K$10:$K$20". Change this reference to the cells where you have the content you would like to display and you should be good to go.
Best regards Christian
ThisWorkbook.Worksheets("Scatter Plot").ChartObjects(1).Chart.SeriesCollection(1).DataLabels.Format.TextFrame2.TextRange. InsertChartField msoChartFieldRange, "=Sheet1!$K$10:$K$20", 0
Then add the following to also display them properly:
With ThisWorkbook.Worksheets("Scatter Plot").ChartObjects(1).Chart.SeriesCollection(1).
.ShowRange = True
.ShowCategoryName = False
.ShowValue = False
End With
Upvotes: 1