3

I have a chart object, with 3 series. The series are getting the Y-values from ranges C1:C10, D1:D10 and E1:E10. The value depends on the values in A1:A10 (eg C1 = A1+6); but I'm charting the values against the values in B1:10 (its a Log-Normal graph).

I'm calculating the values in VBA. Since there is only a discrete number of points in A1:A10, I'd like to add some extra points of interest to the chart. So if A1:A10 contains the integers 1 to 10, I'd like to plot a decimal number like 3.5, without having to add any new rows to the worksheet.

From looking around, I'd assume it would be something with the Extend method ( MSDN - Extend Method ) but I'm not sure how to:

  1. Extend a specific series (like only add a point to series C1:C10 and D1:D10
  2. How to add a data point without requiring to add a cell to the worksheet.

Any help would be appreciated. Thanks

1 Answer 1

5

Question 2

You can set the values on an individual series by using the value property on the series object.

However, in Help, it states that the values in a series can either be

a range on a worksheet or an array of constant values,

but not both.

This means that if you want to specify the series values as a range such as C1:C10, then I think you'll have to add cells if you want to add data points in the series.

If you don't want to add a cell, then you have to specify all values as an array constant.

Question 1

To add data points to a specific series, I believe you would have to select the series, and modify the Values and XValues properties.

Example:

Put this data in the "Sheet1" of Excel and graph it as "Chart1". y1 will be series 1, y2 will be series2 and y3 will be series 3.

     A    B     C     D
1    x    y1    y2    y3
2    1    10    100   400
3    2    20    200   500
4    3    30    300   600

Now, lets add a data point to y2.

     A    B     C     D
1    x    y1    y2    y3
2    1    10    100   400
3    2    20    200   500
4    3    30    300   600
5    4          1000

We have to select the series (by number or by name, in this case, 2 or "y2") and set the Value property to "C2:C5"

'using ranges
Charts("chart1").SeriesCollection("y2").Values = Worksheets("Sheet1").Range("C2:C5")

'using array constant
Charts("chart1").SeriesCollection("y2").Values = Array(100, 200, 300, 1000)

We'll also change the XValues property so that every Value has an XValue

'using ranges
Charts("chart1").SeriesCollection("y2").XValues = Worksheets("Sheet1").Range("A2:A5")

'using array constant
Charts("chart1").SeriesCollection("y2").XValues = Array(1, 2, 3, 4)

Note:

We can have Values as a range and XValues as an array constant or vice versa.

We can also have both Values and XValues as ranges or both as array constants.

We cannot have Values as a range and an array constant.

We cannot have XValues as a range and an array constant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.