Hi Haydar --
Tried sending you email but it bounced (address:
'(e-mail address removed)').
I have a sample spreadsheet to send you if you let me know where to send it.
Here's the text of the message I tried to send:
Hi Haydar
In order to generate a 3d bubble chart, you need to provide 3 data elements
per bubble: the X and Y coordinates of the center of the bubble, and the
diameter.
If you want, you can add a 4th element (color), by specifying more than one
series of cells as you build the chart. In this case, Color tells me to which
‘Family’ a given bubble belongs.
I’m attaching a spreadsheet with data and a chart to illustrate. I’m also
appending a code segment to this message. To use the code, you need to drop
it into a VB macro or sub(procedure).
There’s several hundred lines of code in the Excel app preceding the code
segment below, so some of it may not make sense. I’ll try to give you an
overview:
Basically, I’ve got a DB of about 50 columns by up to 200 rows. Each row
represents an investment opportunity. The Columns contain info related to
each opportunity – risk, reward, cost, ‘family’, projected date of
availability …
The bubble chart portion of the app includes a form which allows the user to
specify several search criteria (delivery date, industry, …), and what values
for each of the opportunities that fit the criteria should be used for X, Y
and Diam. When that’s done, he/she clicks on a button and the app pulls the
relevant info out of the DB and plops it into a new worksheet. As it does so,
it drops the data into the sheet in ‘family’ order, remembering where the
start & end rows are for each family.
In the code snippet below, the filtered & selected data has already been
plopped into a (recently cleared) sheet (“BubbleDataâ€) in the workbook. I’ve
done a global replace on one of my variable names to turn it into
“DataSeries†(think “Familyâ€). Since I don’t know how many Families there
may be in the DB (as time goes by new families of investments may get added),
I have to wander through the db and populate a list of family names and count
how many there are… so there’s a DataSeriesCount (number of
DataSeries/Families found in the DB), a DataSeriesIndex, etc. I also populate
some strings for titles and family names, and for every DataSeries there’s a
string containing the Start of its range and the end of it’s range (in the
sheet “BubbleDataâ€). I tried passing those values as ranges and couldn’t
make it work, but passing them inside a string worked.
Disclaimer: I’m new to VB (this is my first VB app) so there may be
easier/more elegant ways to do what I’ve done here… but I got this to work,
so I stopped ‘improving’ it... Except I would like to be able to see the
specific name of the opportunity when I mouse over the resulting bubble,
instead of the X, Y and Diam values… Haven’t figured out how to do that yet.
In the code snippet below, I have previously determined the average x and y
values ( I want the axes to bisect the chart – show me 4 quadrants). And I
have title and Axis strings that let the user see what data fields were used
for X, Y and Diam, as well as other search criteria (filters).
Let me know if this helps. Or not J
Mark Hinrichs
Here’s the VB code:
----------------------------------------------------- cut here
-------------------------------------------------------------------------------
' Build Chart --- Data comes from sheet “BubbleDataâ€, and Chart gets dumped
into sheet “BubbleChartâ€
Charts.Add
ActiveChart.ChartType = xlBubble3DEffect
ActiveChart.SetSourceData Source:=Sheets("BubbleData").Range( _
DataSeriesChartRangeStr(1)), PlotBy:=xlColumns
For DataSeriesIndex = 2 To DataSeriesCount
ActiveChart.SeriesCollection.NewSeries ' Add all new series
before defining ranges & titles
Next DataSeriesIndex
DataSeriesNameStr = DataSeriesName(1)
ActiveChart.SeriesCollection(1).Name = DataSeriesNameStr
For DataSeriesIndex = 2 To DataSeriesCount
DataSeriesNameStr = DataSeriesName(DataSeriesIndex)
ChartRangeStartRowStr = DataSeriesStartRow(DataSeriesIndex) ' cast
integer vals into strings
ChartRangeEndRowStr = DataSeriesEndRow(DataSeriesIndex)
XValsStr = "=BubbleData!R" + ChartRangeStartRowStr + "C2:R" +
ChartRangeEndRowStr + "C2"
YValsStr = "=BubbleData!R" + ChartRangeStartRowStr + "C3:R" +
ChartRangeEndRowStr + "C3"
BubbleSizeStr = "=BubbleData!R" + ChartRangeStartRowStr + "C4:R" +
ChartRangeEndRowStr + "C4"
ActiveChart.SeriesCollection(DataSeriesIndex).XValues = XValsStr
ActiveChart.SeriesCollection(DataSeriesIndex).Name = DataSeriesNameStr
ActiveChart.SeriesCollection(DataSeriesIndex).BubbleSizes =
BubbleSizeStr
ActiveChart.SeriesCollection(DataSeriesIndex).Values = YValsStr
Next DataSeriesIndex
ActiveChart.Location Where:=xlLocationAsObject, Name:="BubbleChart"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = TitleStr
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = XaxisStr
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = YaxisStr
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlCustom
.CrossesAt = YAxisAvg
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlCustom
.CrossesAt = XAxisAvg
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
Set ThisChart =
ActiveSheet.ChartObjects(ActiveSheet.ChartObjects.Count) ' Scale the chart
to consume the region A1 to P37
With Range("A1
37")
ThisChart.Left = .Left
ThisChart.Top = .Top
ThisChart.Width = .Width
ThisChart.Height = .Height
End With