Solved

How to change chart titles and axis VB.Net Excel Charting

Posted on 2012-03-28
2
652 Views
Last Modified: 2012-03-28
I have created a simple chart in a worksheet and need to change the default axis titles but have a problem with syntax.
	
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
   .Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")

   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
Comment
Question by:TeDeSm
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37775853
I think the Location line is the problem as it actually returns a new reference to the chart object, so:
With objChart

   .Name = "Turnover Chart"
   .SetSourceData(Source:=objRange1, PlotBy:=Excel.XlRowCol.xlColumns)
   .ChartType = Excel.XlChartType.xlCylinderColStacked
End With
  objChart = objChart.Location(Where:=Excel.XlChartLocation.xlLocationAsObject, Name:="Chart")
With objChart
   ' THE NEXT LINE THROWS AN EXCEPTION
   objAxis = CType(.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary), Excel.Axis)

   With objAxis
       .HasTitle = True
       .AxisTitle.Text = "Sales"
   End With

End With

Open in new window

0
 

Author Closing Comment

by:TeDeSm
ID: 37776091
I had figured that I had lost the reference to the chart, just couldn't figure out where'

A spot on solution.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now