SetData Method Example

This example creates a chart using literal data arrays.

Dim seriesNames(1)
Dim categories(7)
Dim values(7)

seriesNames(0) = "Satisfaction Data"

categories(0) = "Very Good"
categories(1) = "Good"
categories(2) = "N/A"
categories(3) = "Average"
categories(4) = "No Response"
categories(5) = "Poor"
categories(6) = "Very Poor"

values(0) = 10
values(1) = 22
values(2) = 6
values(3) = 31
values(4) = 5
values(5) = 14
values(6) = 12

Set cht = ChartSpace1.Charts.Add
Set c = ChartSpace1.Constants
cht.Type = c.chChartTypeColumnClustered

cht.SetData c.chDimSeriesNames, c.chDataLiteral, seriesNames
cht.SetData c.chDimCategories, c.chDataLiteral, categories
cht.SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values

This example creates a chart that is bound to a spreadsheet. The series name is in cell B1, the category names are in cells A2:A28, and the values are in cells B2:B28.

Set c = ChartSpace1.Constants
Set ChartSpace1.DataSource = Spreadsheet1
ChartSpace1.Charts.Add
ChartSpace1.Charts(0).Type = c.chChartTypeLineMarkers
ChartSpace1.Charts(0).SetData c.chDimSeriesNames, 0, "b1"
ChartSpace1.Charts(0).SetData c.chDimCategories, 0, "a2:a28"
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, 0, "b2:b28"