Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-03-28
2
657 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

856 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