?
Solved

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

Posted on 2012-03-28
2
Medium Priority
?
672 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
[X]
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
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

801 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